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

remove actions from props #45

Closed
threepointone opened this issue Jun 6, 2015 · 7 comments
Closed

remove actions from props #45

threepointone opened this issue Jun 6, 2015 · 7 comments

Comments

@threepointone
Copy link

Was wondering how you handle clashing action and store names in containers. But it also strikes me that since actions are just functions without a current state, they don't have to be passed down from the top. Instead, as long as the dispatch function is available as a prop, you'll still be able to do full dispatches. to explain, instead of -

@inject({
  actions: CounterActions,
  stores: { counter: counterStore }
})
export default class Counter {
  render() {
    const { increment, decrement, counter } = this.props;
    return (
      <p>
        <button onClick={increment}>+</button>
      </p>
    );
  }

you could do

@inject({
  stores: { counter: counterStore }
})
export default class Counter {
  static propTypes = {
    dispatch: PropTypes.func.isRequired
  };

  render() {
    const { counter, dispatch } = this.props;
    return (
      <p>
        Clicked: {counter} times
        {' '}
        <button onClick={() => dispatch(increment())}>+</button>
        {' '}
        <button onClick={() => dispatch(decrement())}>-</button>
      </p>
    );
  }

alternately

        <button onClick={() => dispatch(increment)}>+</button>

but I'm not clear on the benefits (scheduling?)

This would clear up the name clash problem, and make it more 'primitive', if that make sense.

@threepointone
Copy link
Author

also, you could then read state from stores when calling dispatch, preventing the need for read/storeKeys

@threepointone
Copy link
Author

thinking more, anyone could implement any action creator system on top of this. promises, observables, etc.

[it's starting to look like cycle, but more accessible]

@gaearon
Copy link
Contributor

gaearon commented Jun 6, 2015

cc @acdlite who was also rethinking Redux. Indeed, I want to move this action creator <-> dispatch thing out of the core.

@gaearon
Copy link
Contributor

gaearon commented Jun 6, 2015

This is done now in #46, let's discuss there.

@gaearon gaearon closed this as completed Jun 6, 2015
@gaearon
Copy link
Contributor

gaearon commented Jun 6, 2015

#46 (comment)

@threepointone
Copy link
Author

Wow lots going on there. I want to hack on a project tonight with this, will come back with thoughts. Cheers.

@gaearon
Copy link
Contributor

gaearon commented Jun 6, 2015

Out in 0.8.0

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

2 participants