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

adding Reflux.connect #75

Merged
merged 3 commits into from
Sep 23, 2014
Merged

adding Reflux.connect #75

merged 3 commits into from
Sep 23, 2014

Conversation

krawaller
Copy link
Contributor

After several iterations, I think I've arrived at a good convenience method for the common use case when you want to make a React component set its state to whatever a listenable returns.

This pull request exposes Reflux.connect(listenable,[stateKey]), intented to be used as a mixin much like Reflux.listenTo. If stateKey is supplied then it will do setState({<stateKey>:data}), otherwise just setState(data).

Here's the Reflux.listenTo example from the README:

var Status = React.createClass({
    mixins: [Reflux.listenTo(statusStore,"onStatusChange")],
    onStatusChange: function(status) {
        this.setState({
            currentStatus: status
        });
    },
    render: function() {
        // render specifics
    }
});

...which using Reflux.connect instead can be reduced to this:

var Status = React.createClass({
    mixins: [Reflux.connect(statusStore,"currentStatus")],
    render: function() {
        // render specifics
    }
});

Isn't it beatiful? Absolutely nothing boilerplaty whatsoever! :)

I found in my Reflux app I could almost always use Reflux.connect as it was only in very rare cases that I needed to do some special logic.

@krawaller krawaller mentioned this pull request Sep 23, 2014
var Status = React.createClass({
mixins: [Reflux.connect(statusStore,"currentStatus")],
render: function() {
// render specifics
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more clear about it, comment should say that you can use this.state.currentStatus in the render method. In tandem with what the documentation says above the example, since that's where the state variable (given by the key) will practically be used.

@spoike spoike added this to the 0.1.8 milestone Sep 23, 2014
@spoike
Copy link
Member

spoike commented Sep 23, 2014

@krawaller could you fix the merge conflict?

@krawaller
Copy link
Contributor Author

Nod, will be home in a few hours! Good point about the code example, will fix that too at the same time.

@spoike
Copy link
Member

spoike commented Sep 23, 2014

Cool. Will be much appreciated. Hopefully we can make a release for 0.1.8 like... soonish. :-)

@krawaller
Copy link
Contributor Author

Conflict fixed, examples updated.

spoike added a commit that referenced this pull request Sep 23, 2014
@spoike spoike merged commit 03df335 into reflux:0.1.8 Sep 23, 2014
@spoike
Copy link
Member

spoike commented Sep 23, 2014

Cool. Thanks!

@krawaller krawaller deleted the connect branch October 2, 2014 06:47
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

Successfully merging this pull request may close these issues.

2 participants