tonyhb / redux-ui

Easy UI state management for react redux
636 stars 58 forks source link

The reducer in options depends on the order of component #76

Open FailLone opened 7 years ago

FailLone commented 7 years ago

order: <Toolbar /> <Table />

ui in Toolbar:

@ui({
    key: 'table',
    state: {
        selected: Immutable.Map()
    }
})

ui in Table:

@ui({
  key: 'table',
  state: {
    selected: Immutable.Map(),
    loading: false,
  },
  reducer: (state, action) => {
    switch (action.type) {
      case 'FETCH':
        return state.set('loading', true)
      default:
        return state
    }
  }
})

this reducer is invalid, because the HOC ui bind reducer as follows:

componentWillMount() {
     // If the component's UI subtree doesn't exist and we have state to
    // set ensure we update our global store with the current state.
    if (this.props.ui.getIn(this.uiPath) === undefined && opts.state) {
        const state = this.getDefaultUIState(opts.state);
        this.context.store.dispatch(mountUI(this.uiPath, state, opts.reducer));
     }
}

i dont think this is a bug, but i dont like handle the state of Table in Toolbar, it there any good idea?