unirakun / k-redux-factory

Factory of Redux reducers and their associated actions and selectors.
MIT License
18 stars 4 forks source link

Benefits of k-redux-factory selectors #158

Open delphinemillet opened 5 years ago

delphinemillet commented 5 years ago

Sometimes, accessing an object in the state from a container is quickier to write than using its selector. I would like to know all the advantages of k-redux-factory selectors over the direct use the state.

fabienjuif commented 5 years ago

k-redux-factory is a lib that aim to access your data as fast as possible. By using selectors you are safe about our possible internal state restructurations.

For example, we move from keyValue like that:

In this example if you didn't use our selectors, an upgrade of k-redux-factory could break your application. But if you used our selectors, it wouldn't.

Always prefers using lib API and not its internals, when you can!


Besides that I see these advantages:

  1. We (k-redux-factory) can refactor our code without breaking your application (see previous comment)
  2. You have a standard, always use selectors
  3. You can move your factory around your store definition -> your containers will not have to be fixed
  4. You can memoize selectors if you need to at some point
fabienjuif commented 5 years ago

moreover, if you want to try k-ramel, you can access the state using k-redux-factory selectors in a quick way:

export default inject(store => ({
  users: store.data.users.get(),
})(Component)

https://github.com/alakarteio/k-ramel