UNPKG

2.47 kBTypeScriptView Raw
1import { StoryGetter, StoryContext, Args } from './types';
2interface Hook {
3 name: string;
4 memoizedState?: any;
5 deps?: any[] | undefined;
6}
7interface Effect {
8 create: () => (() => void) | void;
9 destroy?: (() => void) | void;
10}
11declare type Decorator = (getStory: StoryGetter, context: StoryContext) => any;
12declare type AbstractFunction = (...args: any[]) => any;
13export declare class HooksContext {
14 hookListsMap: WeakMap<AbstractFunction, Hook[]>;
15 mountedDecorators: Set<AbstractFunction>;
16 prevMountedDecorators: Set<AbstractFunction>;
17 currentHooks: Hook[];
18 nextHookIndex: number;
19 currentPhase: 'MOUNT' | 'UPDATE' | 'NONE';
20 currentEffects: Effect[];
21 prevEffects: Effect[];
22 currentDecoratorName: string | null;
23 hasUpdates: boolean;
24 currentContext: StoryContext | null;
25 renderListener: () => void;
26 constructor();
27 init(): void;
28 clean(): void;
29 getNextHook(): Hook;
30 triggerEffects(): void;
31 addRenderListeners(): void;
32 removeRenderListeners(): void;
33}
34export declare const applyHooks: (applyDecorators: (getStory: StoryGetter, decorators: Decorator[]) => StoryGetter) => (getStory: StoryGetter, decorators: Decorator[]) => (context: StoryContext) => any;
35export declare function useMemo<T>(nextCreate: () => T, deps?: any[]): T;
36export declare function useCallback<T>(callback: T, deps?: any[]): T;
37export declare function useRef<T>(initialValue: T): {
38 current: T;
39};
40export declare function useState<S>(initialState: (() => S) | S): [S, (update: ((prevState: S) => S) | S) => void];
41export declare function useReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S): [S, (action: A) => void];
42export declare function useReducer<S, I, A>(reducer: (state: S, action: A) => S, initialArg: I, init: (initialArg: I) => S): [S, (action: A) => void];
43export declare function useEffect(create: () => (() => void) | void, deps?: any[]): void;
44export interface Listener {
45 (...args: any[]): void;
46}
47export interface EventMap {
48 [eventId: string]: Listener;
49}
50export declare function useChannel(eventMap: EventMap, deps?: any[]): any;
51export declare function useStoryContext(): StoryContext;
52export declare function useParameter<S>(parameterKey: string, defaultValue?: S): S | undefined;
53export declare function useArgs(): [Args, (newArgs: Args) => void, (argNames?: [string]) => void];
54export declare function useGlobals(): [Args, (newGlobals: Args) => void];
55export {};