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

Conversation

Projects
None yet
2 participants
@krawaller
Contributor

krawaller commented Sep 18, 2014

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 referenced this pull request Sep 23, 2014

Merged

0.1.8 #67

Show outdated Hide outdated README.md

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

@spoike

This comment has been minimized.

Show comment
Hide comment
@spoike

spoike Sep 23, 2014

Member

@krawaller could you fix the merge conflict?

Member

spoike commented Sep 23, 2014

@krawaller could you fix the merge conflict?

@krawaller

This comment has been minimized.

Show comment
Hide comment
@krawaller

krawaller Sep 23, 2014

Contributor

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

Contributor

krawaller commented Sep 23, 2014

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

@spoike

This comment has been minimized.

Show comment
Hide comment
@spoike

spoike Sep 23, 2014

Member

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

Member

spoike commented Sep 23, 2014

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

@krawaller

This comment has been minimized.

Show comment
Hide comment
@krawaller

krawaller Sep 23, 2014

Contributor

Conflict fixed, examples updated.

Contributor

krawaller commented Sep 23, 2014

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

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@spoike

This comment has been minimized.

Show comment
Hide comment
@spoike

spoike Sep 23, 2014

Member

Cool. Thanks!

Member

spoike commented Sep 23, 2014

Cool. Thanks!

@krawaller krawaller deleted the krawaller:connect branch Oct 2, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment