Skip to content

Commit 904e372

Browse files
committed
Update types
1 parent c1ac7ea commit 904e372

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@storybook/addon-devkit",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "Storybook Addon Development Kit",
55
"author": {
66
"name": "Oleg Proskurin",

src/index.d.ts

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
type Store = {
2-
[key: string]: any
3-
};
1+
import { types as addonTypes } from '@storybook/addons'
2+
import { API } from '@storybook/api'
3+
4+
interface Dictionary<T = any> {
5+
[key: string]: T
6+
}
7+
8+
type AddonStore = Dictionary;
49

5-
type Selector = (store: Store) => any;
10+
type Selector = (store: AddonStore) => any;
611
type ParamSelector = (parameters: {
712
[key: string]: any
813
}, selectors: {
@@ -11,18 +16,19 @@ type ParamSelector = (parameters: {
1116

1217
type ActionDispatcher = (...args: any[]) => void | Promise<void>;
1318
type ActionGenerator = (
14-
action: (store: Store, ...args: any[]) => Store | Promise<Store>
19+
action: (store: AddonStore, ...args: any[]) => AddonStore | Promise<AddonStore>
1520
) => ActionDispatcher;
16-
type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => {
17-
[key: string]: ActionDispatcher
18-
};
21+
type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => Dictionary<ActionDispatcher>;
22+
23+
type RegisterOptions = {
24+
type?: addonTypes
25+
initData?: Dictionary
26+
}
1927

2028
export declare function register(
21-
storeSelectors: {
22-
[key: string]: Selector
23-
},
24-
createActions: Actions
25-
): (Component: React.ComponentType) => void;
29+
storeSelectors?: Dictionary<Selector>,
30+
createActions?: Actions
31+
): (Component: React.ComponentType, options: RegisterOptions) => void;
2632

2733

2834
interface StoryContext {
@@ -43,18 +49,40 @@ type DecoratorOptions = {
4349
isGlobal: boolean,
4450
}
4551

46-
export declare function createDecorator(storeSelectors: {
47-
[key: string]: Selector
48-
},
52+
export declare function createDecorator(storeSelectors?: Dictionary<Selector>,
4953
createActions: Actions,
50-
paramSelectors: {
51-
[key: string]: ParamSelector
52-
}
54+
paramSelectors?: Dictionary<
55+
(parameters: Dictionary, selectors: Dictionary<() => any>) => any
56+
>
5357
): (Component: React.ComponentType, options: DecoratorOptions) => DecoratorFunction;
5458

55-
type AddonParameters = {
56-
[key: string]: any
57-
}
59+
type AddonParameters = Dictionary<any>
60+
5861
export declare function setParameters(): <T extends AddonParameters>(T) => ({
59-
addonKey: T
62+
[ConfigValues.PARAM_Key]: T
6063
})
64+
65+
type ConfigOptions = {
66+
addonId?: string
67+
panelId?: string
68+
panelTitle?: string
69+
paramKey?: string
70+
eventInit?: string
71+
eventData?: string
72+
eventBack?: string
73+
}
74+
75+
export declare function setConfig(config: ConfigOptions): void
76+
77+
type ConfigValues = {
78+
ADDON_ID: string
79+
PANEL_ID: string
80+
PANEL_Title: string
81+
PARAM_Key: string
82+
EVENT_ID_INIT: string
83+
EVENT_ID_DATA: string
84+
EVENT_ID_BACK: string
85+
}
86+
87+
export declare function getConfig(): ConfigValues
88+

0 commit comments

Comments
 (0)