Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
usulpro committed Jan 26, 2020
1 parent c1ac7ea commit 904e372
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-devkit",
"version": "1.3.3",
"version": "1.3.4",
"description": "Storybook Addon Development Kit",
"author": {
"name": "Oleg Proskurin",
Expand Down
74 changes: 51 additions & 23 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
type Store = {
[key: string]: any
};
import { types as addonTypes } from '@storybook/addons'
import { API } from '@storybook/api'

interface Dictionary<T = any> {
[key: string]: T
}

type AddonStore = Dictionary;

type Selector = (store: Store) => any;
type Selector = (store: AddonStore) => any;
type ParamSelector = (parameters: {
[key: string]: any
}, selectors: {
Expand All @@ -11,18 +16,19 @@ type ParamSelector = (parameters: {

type ActionDispatcher = (...args: any[]) => void | Promise<void>;
type ActionGenerator = (
action: (store: Store, ...args: any[]) => Store | Promise<Store>
action: (store: AddonStore, ...args: any[]) => AddonStore | Promise<AddonStore>
) => ActionDispatcher;
type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => {
[key: string]: ActionDispatcher
};
type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => Dictionary<ActionDispatcher>;

type RegisterOptions = {
type?: addonTypes
initData?: Dictionary
}

export declare function register(
storeSelectors: {
[key: string]: Selector
},
createActions: Actions
): (Component: React.ComponentType) => void;
storeSelectors?: Dictionary<Selector>,
createActions?: Actions
): (Component: React.ComponentType, options: RegisterOptions) => void;


interface StoryContext {
Expand All @@ -43,18 +49,40 @@ type DecoratorOptions = {
isGlobal: boolean,
}

export declare function createDecorator(storeSelectors: {
[key: string]: Selector
},
export declare function createDecorator(storeSelectors?: Dictionary<Selector>,
createActions: Actions,
paramSelectors: {
[key: string]: ParamSelector
}
paramSelectors?: Dictionary<
(parameters: Dictionary, selectors: Dictionary<() => any>) => any
>
): (Component: React.ComponentType, options: DecoratorOptions) => DecoratorFunction;

type AddonParameters = {
[key: string]: any
}
type AddonParameters = Dictionary<any>

export declare function setParameters(): <T extends AddonParameters>(T) => ({
addonKey: T
[ConfigValues.PARAM_Key]: T
})

type ConfigOptions = {
addonId?: string
panelId?: string
panelTitle?: string
paramKey?: string
eventInit?: string
eventData?: string
eventBack?: string
}

export declare function setConfig(config: ConfigOptions): void

type ConfigValues = {
ADDON_ID: string
PANEL_ID: string
PANEL_Title: string
PARAM_Key: string
EVENT_ID_INIT: string
EVENT_ID_DATA: string
EVENT_ID_BACK: string
}

export declare function getConfig(): ConfigValues

0 comments on commit 904e372

Please sign in to comment.