Skip to content

Commit

Permalink
#14: improve naming and typing readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Y. Li committed Apr 18, 2019
1 parent 8fb01c7 commit 11a0e9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions addons/addon-contexts/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ export declare type PropsMapUpdaterType = (

// helper types
export declare type AggregateComponents = <T>(
h: (...arg: any[]) => T
) => (...arg: [ComponentType[], GenericProps, AddonOptions, number]) => AnyFunctionReturns<T>;
h: AnyFunctionReturns<T>
) => (...args: [ComponentType[], GenericProps, AddonOptions, number]) => AnyFunctionReturns<T>;
export declare type AggregateContexts = <T>(
h: (...arg: any[]) => T
) => (...arg: [ContextNode[], Exclude<GenericProps, null>]) => AnyFunctionReturns<T>;
h: AnyFunctionReturns<T>
) => (...args: [ContextNode[], Exclude<GenericProps, null>]) => AnyFunctionReturns<T>;
export declare type MergeSettings = (
...args: [Partial<AddonSetting>, Partial<AddonSetting>]
) => ContextNode;
export declare type GetContextNodes = (settings: WrapperSettings) => ContextNode[];
export declare type Memorize = <T, U extends any[]>(
fn: (...arg: U) => T,
resolver: (...arg: U) => unknown
) => (...arg: U) => T;
fn: (...args: U) => T,
resolver: (...args: U) => unknown
) => (...args: U) => T;
export declare type UseChannel = (
event: string,
eventHandler: AnyFunctionReturns<void>,
input?: unknown[]
) => void;

// Component types
export declare type Wrapper = (...arg: [Function, unknown, WrapperSettings]) => ReactNode;
export declare type Wrapper = (...args: [Function, unknown, WrapperSettings]) => unknown;
export declare type TAddonManager = FCNoChildren<{
channel: Channel;
}>;
Expand All @@ -83,7 +83,7 @@ export declare type TAddonWrapper = FC<{
export declare type TMenuController = FCNoChildren<
Omit<
ContextNode & {
setSelect: (...arg: StringTuple) => void;
setSelect: (...args: StringTuple) => void;
},
'components'
>
Expand Down
4 changes: 2 additions & 2 deletions addons/addon-contexts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { createElement as h } from 'react';
import addons, { makeDecorator } from '@storybook/addons';
import { ReactWrapper } from './containers/ReactWrapper';
import { ID, PARAM } from './libs/constants';
import { getNodes } from './libs/helpers';
import { getContextNodes } from './libs/helpers';
import { WithContexts, Wrapper } from './@types';

const wrapper: Wrapper = (getStory, context, settings) => {
const nodes = getNodes(settings);
const nodes = getContextNodes(settings);
return h(ReactWrapper, {
nodes,
channel: addons.getChannel(),
Expand Down
2 changes: 1 addition & 1 deletion addons/addon-contexts/src/libs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ export const aggregateContexts: AggregateContexts = (h) => (nodes, propsMap) =>
)
.reduce((acc, agg) => agg(() => acc), next());

export const getNodes = _memorize(_getContextNodes, ({ parameters }) => parameters);
export const getContextNodes = _memorize(_getContextNodes, ({ parameters }) => parameters);

0 comments on commit 11a0e9d

Please sign in to comment.