Skip to content

Instantly share code, notes, and snippets.

@andycarrell
Last active May 3, 2019 01:38
Show Gist options
  • Save andycarrell/8c877934ee781fdd8db18d575dddd6d8 to your computer and use it in GitHub Desktop.
Save andycarrell/8c877934ee781fdd8db18d575dddd6d8 to your computer and use it in GitHub Desktop.
const composeDecorators = (first, ...decorators) =>
decorators.reduce(
(accumulatedDecorators, nextDecorator) => storyFn =>
accumulatedDecorators(() => nextDecorator(storyFn)),
first,
);
// please don't
const ds = (i, ...r) => r.reduce((a, d) => f => a(() => d(f)), i);
// usage
.addDecorator(composeDecorators(
withKnobs,
withCustomDecorator,
storyFn => <div style={{ textAlign: "center" }}>{storyFn()}</div>,
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment