Skip to content

actions and dispatch #23

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

Closed
maxguzenski opened this issue Aug 6, 2015 · 4 comments
Closed

actions and dispatch #23

maxguzenski opened this issue Aug 6, 2015 · 4 comments

Comments

@maxguzenski
Copy link

First at all, thanks for build redux.

I read all discussion on #1 but I still don't get it:

Why Provider/Connection decoration just doesn't bind all actions creator to dispatch only once (willComponentMount or something like that) and pass it (all app actions) to nested component as props?

With the new api proposal, I still have to pass to @connect that actions that I want to use, and its look like to been "re bind" all time that render() is called... I just dont get why.. what have I missed?

@gnoff
Copy link
Contributor

gnoff commented Aug 6, 2015

in #16 the binding of action creators happens during mounting only one time.

If you want to pass all app actions to all subcomponents using the new api you can do so trivially by passing all of your actions into the second argument (see example below). We wouldn't want to do that for you automatically however since it would cut off other use cases and possibly pollute connected components with unnecessary or redundant actions (imagine nested connected components for a email client where you have navigational actions for what messages are being viewed but then a component for the actual message detail view, not that this would be the optimal setup)

@connect(
  State => State,
  require('./path/to/module/that/contains/allActions')
)

@gaearon
Copy link
Contributor

gaearon commented Aug 6, 2015

That's exactly the intention for the new API. It is connect(selectState, mapDispatch, mergeProps). While selectState is called every time store state changes, mapDispatch is only called once.

@gaearon gaearon closed this as completed Aug 6, 2015
@maxguzenski
Copy link
Author

Yes, but it looks like that you have to pass actions on @connect, why not and @connect just pass it forward all the time?

@gnoff
Copy link
Contributor

gnoff commented Aug 7, 2015

Actions are attached to connected components as props. Passing all actions all the time would unnecessarily pollute props of all connected components and would greatly increase the likelihood of overloading a prop and hiding an intended behavior. In more complicated apps it doesn't make sense for all components to be aware of all actions and therefore this behavior you suggest would hinder the majority for the convenience of a few

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

3 participants