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

Add getInititalData() to Store #46

Merged
merged 2 commits into from Aug 20, 2014

Conversation

Projects
None yet
2 participants
@SimonDegraeve
Contributor

SimonDegraeve commented Aug 17, 2014

Add the getInitialData() method to Store as mentioned in #44.
This method is called when an optional third argument is provided to listenTo in a React Component using the ListenerMixin.

Example:

var aStore = Reflux.createStore({
    init: function() {
        this.listenTo(anAction, function() {
            this.trigger('not initial data anymore');
        });
    }
    getInitialData: function() {
        return 'the initial data'; // Can also return a Promise
    }
});

var Component = React.createClass({
    mixins: [Reflux.ListenerMixin],
    getInitialState: function() {
        return {};
    },
    componentDidMount: function() {
        this.listenTo(
            aStore, 
            changeCallback, 
            changeCallback // This callback is optional, execute getInitialData from aStore
        );
    },
    changeCallback: function(data) {
        console.log(data);
        this.setState({
            data: data
        });
    }
});

TODO:

  • write the tests
initialCallback(data);
}
}
}

This comment has been minimized.

@spoike

spoike Aug 17, 2014

Member

Since this part of the listenTo method (L24-34) is exactly the same in both createStore and ListenerMixin it'd be nice to have this extracted to a function in src/utils.js (in order to avoid double maintenance).

Something like _.handleInitialData(listenable, initialCallback).

@spoike

spoike Aug 17, 2014

Member

Since this part of the listenTo method (L24-34) is exactly the same in both createStore and ListenerMixin it'd be nice to have this extracted to a function in src/utils.js (in order to avoid double maintenance).

Something like _.handleInitialData(listenable, initialCallback).

@SimonDegraeve

This comment has been minimized.

Show comment
Hide comment
@SimonDegraeve

SimonDegraeve Aug 17, 2014

Contributor

Indeed. I will update it when I go home. Any other suggestions?

Contributor

SimonDegraeve commented Aug 17, 2014

Indeed. I will update it when I go home. Any other suggestions?

@spoike

This comment has been minimized.

Show comment
Hide comment
@spoike

spoike Aug 17, 2014

Member

I'll accept this PR once there are tests for it. :-)

Member

spoike commented Aug 17, 2014

I'll accept this PR once there are tests for it. :-)

@undoZen undoZen referenced this pull request Aug 18, 2014

Merged

Get default data #49

@spoike spoike merged commit baefab9 into reflux:master Aug 20, 2014

1 check passed

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

@spoike spoike referenced this pull request Sep 4, 2014

Closed

Asynchronous dataflow example #57

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