@@ -26,73 +26,73 @@ const withChannel = ({
2626 storeSelectors = { } ,
2727 createActions = { } ,
2828} ) => WrappedComponent =>
29- class extends React . Component {
30- static displayName = `WithChannel(${ getDisplayName ( WrappedComponent ) } )` ;
31-
32- constructor ( props , ...args ) {
33- super ( props , ...args ) ;
34- const initStateData = {
35- ...initData ,
36- ...props . initData ,
37- ...parameters ,
38- } ;
29+ class extends React . Component {
30+ static displayName = `WithChannel(${ getDisplayName ( WrappedComponent ) } )` ;
31+
32+ constructor ( props , ...args ) {
33+ super ( props , ...args ) ;
34+ const initStateData = {
35+ ...initData ,
36+ ...props . initData ,
37+ ...parameters ,
38+ } ;
3939
40- const isReceived = false ;
40+ const isReceived = false ;
4141
42- this . state = {
43- data : initStateData ,
44- selectors : isReceived ? this . prepareSelectors ( initStateData ) : { } ,
42+ this . state = {
43+ data : initStateData ,
44+ selectors : isReceived ? this . prepareSelectors ( initStateData ) : { } ,
4545 isReceived,
4646 } ;
4747
4848 this . store = ( panel ? getSingleStore : getNewStore ) ( {
4949 EVENT_ID_INIT ,
5050 EVENT_ID_DATA ,
5151 EVENT_ID_BACK ,
52- name : props . pointName ,
53- initData : this . state . data ,
54- isPanel : this . isPanel ,
55- storyId,
56- } ) ;
52+ name : props . pointName ,
53+ initData : this . state . data ,
54+ isPanel : this . isPanel ,
55+ storyId,
56+ } ) ;
5757
58- this . actions = this . prepareActions ( ) ;
59- }
58+ this . actions = this . prepareActions ( ) ;
59+ }
6060
61- isPanel = this . props . panel || panel ;
61+ isPanel = this . props . panel || panel ;
6262
63- prepareSelectors = store => {
64- return Object . entries ( storeSelectors )
65- . map ( ( [ name , selector ] ) => ( {
66- [ name ] : tryToSelect ( selector ) ( store ) ,
67- } ) )
68- . reduce ( ( akk , cur ) => ( { ...akk , ...cur } ) , { } ) ;
69- } ;
63+ prepareSelectors = store => {
64+ return Object . entries ( storeSelectors )
65+ . map ( ( [ name , selector ] ) => ( {
66+ [ name ] : tryToSelect ( selector ) ( store ) ,
67+ } ) )
68+ . reduce ( ( akk , cur ) => ( { ...akk , ...cur } ) , { } ) ;
69+ } ;
7070
71- prepareActions = ( ) => {
72- const {
73- createGlobalAction : global ,
74- createLocalAction : local ,
75- } = this . store ;
76- const isFn = typeof createActions === 'function' ;
77- const actions = isFn
78- ? createActions ( { global, local } )
79- : Object . entries ( createActions )
71+ prepareActions = ( ) => {
72+ const {
73+ createGlobalAction : global ,
74+ createLocalAction : local ,
75+ } = this . store ;
76+ const isFn = typeof createActions === 'function' ;
77+ const actions = isFn
78+ ? createActions ( { global, local } )
79+ : Object . entries ( createActions )
8080 . map ( ( [ name , reducer ] ) => ( { [ name ] : global ( reducer ) } ) )
8181 . reduce ( ( acc , cur ) => ( { ...acc , ...cur } ) , { } ) ;
82- return actions ;
83- } ;
82+ return actions ;
83+ } ;
8484
85- componentDidMount ( ) {
86- this . debugLog ( 'componentDidMount' ) ;
87- this . store . onData ( this . onData ) ;
88- if ( this . state . data && ! this . isPanel ) {
89- this . store . onConnected ( ( ) => this . store . sendInit ( this . state . data ) ) ;
85+ componentDidMount ( ) {
86+ this . debugLog ( 'componentDidMount' ) ;
87+ this . store . onData ( this . onData ) ;
88+ if ( this . state . data && ! this . isPanel ) {
89+ this . store . onConnected ( ( ) => this . store . sendInit ( this . state . data ) ) ;
90+ }
91+ this . store . connect ( ) ;
9092 }
91- this . store . connect ( ) ;
92- }
9393
94- componentWillUnmount ( ) {
95- this . debugLog ( 'componentWillUnmount' ) ;
94+ componentWillUnmount ( ) {
95+ this . debugLog ( 'componentWillUnmount' ) ;
9696 this . store . disconnect ( ) ;
9797 }
9898
@@ -101,43 +101,43 @@ const withChannel = ({
101101
102102 debugLog = message => {
103103 if ( ! this . debug ) {
104- return ;
105- }
106- console . log (
107- this . store . isPanel ? 'Panel:\n' : 'Preview:\n' ,
108- message ,
109- this . store . store
110- ) ;
111- } ;
104+ return ;
105+ }
106+ console . log (
107+ this . store . isPanel ? 'Panel:\n' : 'Preview:\n' ,
108+ message ,
109+ this . store . store
110+ ) ;
111+ } ;
112112
113- onData = data => {
114- this . setState ( {
115- data,
116- isReceived : true ,
117- selectors : this . prepareSelectors ( data ) ,
118- } ) ;
119- } ;
113+ onData = data => {
114+ this . setState ( {
115+ data,
116+ isReceived : true ,
117+ selectors : this . prepareSelectors ( data ) ,
118+ } ) ;
119+ } ;
120120
121- render ( ) {
122- const { pointName, initData, active, onData, ...props } = this . props ;
123- const { data, isReceived, selectors } = this . state ;
124-
125- if ( active === false ) return null ;
126-
127- return (
128- < WrappedComponent
129- data = { data }
130- setData = { this . store . send }
131- store = { this . store }
132- active = { active }
133- parameters = { parameters }
134- selectors = { selectors }
135- actions = { this . actions }
136- isFirstDataReceived = { isReceived }
137- { ...props }
138- />
139- ) ;
140- }
141- } ;
121+ render ( ) {
122+ const { pointName, initData, active, onData, ...props } = this . props ;
123+ const { data, isReceived, selectors } = this . state ;
124+
125+ if ( active === false ) return null ;
126+
127+ return (
128+ < WrappedComponent
129+ data = { data }
130+ setData = { this . store . send }
131+ store = { this . store }
132+ active = { active }
133+ parameters = { parameters }
134+ selectors = { selectors }
135+ actions = { this . actions }
136+ isFirstDataReceived = { isReceived }
137+ { ...props }
138+ />
139+ ) ;
140+ }
141+ } ;
142142
143143export default withChannel ;
0 commit comments