Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: allow state param to be object _or_ function #6

Open
jameslaneconkling opened this issue May 11, 2018 · 0 comments
Open

Proposal: allow state param to be object _or_ function #6

jameslaneconkling opened this issue May 11, 2018 · 0 comments

Comments

@jameslaneconkling
Copy link

jameslaneconkling commented May 11, 2018

Currently, state object type (POJO or Immutable.js collection or whathaveyou) can be configured by passing a third argument to the reducer function

combineReducers({
  ...reducers,
  ui: (state, action) => ui( state, action, Map )
})

And keys in the ui state tree can be either keys or functions in order that they can be initialized based on component props.

@ui({
  state: {
    uiVar1: '',
    uiVar2: (props, state) => state.router.location.query.searchTerm
  },
  ...
})

Proposal: allowing the entire state param to be either an object or a function could simplify the above two features, and result in fewer function calls when initializing the state.

E.g.

// state as plain object
@ui({
  state: {
    uiVar1: 'this',
    uiVar2: 'that'
  }
})

// state as function
@ui({
  state: (props, state) => ({
    uiVar1: 'this',
    uiVar2: state.router.location.query.searchTerm
  })
})

// state as function returning Immutable.js collection
@ui({
  state: (props, state) => Immutable.Map({
    uiVar1: 'this',
    uiVar2: state.router.location.query.searchTerm
  })
})

Any issues/cases I'm not covering here?

If you're interested in this extension to the API, I'd be happy to submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant