@@ -3,14 +3,47 @@ import withChannel from './withChannel';
33
44import { getConfig } from './config' ;
55
6- const DecoratorHOC = ( { actions, selectors, Component, parameters, resetParameters, ...props } ) => {
7- return < Component { ...actions } { ...selectors } { ...props } />
6+ const createHOC = paramSelectors => {
7+ const DecoratorWrapper = ( {
8+ actions,
9+ selectors,
10+ Component,
11+ parameters,
12+ resetParameters,
13+ ...props
14+ } ) => {
15+ let params = { } ;
16+ if ( paramSelectors ) {
17+ try {
18+ const entries = Object . entries ( paramSelectors ) ;
19+ const paramResults = entries
20+ . map ( ( [ name , fn ] ) => {
21+ try {
22+ return { [ name ] : fn ( parameters , selectors ) } ;
23+ } catch ( err ) {
24+ console . error ( err ) ;
25+ return null ;
26+ }
27+ } )
28+ . filter ( Boolean ) ;
29+ params = paramResults . reduce ( ( obj , item ) => ( { ...obj , ...item } ) , { } ) ;
30+ } catch ( err ) {
31+ console . error ( err ) ;
32+ }
33+ }
34+ return < Component { ...actions } { ...selectors } { ...params } { ...props } /> ;
35+ } ;
36+ return DecoratorWrapper ;
837} ;
938
10- export const createDecorator = ( storeSelectors , createActions ) => (
11- Component ,
12- { isGlobal = true } = { }
13- ) => initData => ( getStory , context ) => {
39+ export const createDecorator = (
40+ storeSelectors ,
41+ createActions ,
42+ paramSelectors
43+ ) => ( Component , { isGlobal = true } = { } ) => initData => (
44+ getStory ,
45+ context
46+ ) => {
1447 const {
1548 ADDON_ID ,
1649 EVENT_ID_INIT ,
@@ -33,7 +66,7 @@ export const createDecorator = (storeSelectors, createActions) => (
3366 storyId,
3467 storeSelectors,
3568 createActions,
36- } ) ( DecoratorHOC ) ;
69+ } ) ( createHOC ( paramSelectors ) ) ;
3770
3871 return (
3972 < WithChannel getStory = { getStory } context = { context } Component = { Component } />
0 commit comments