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

Extend the listener mixin to provide "initial" data #44

Closed
spoike opened this issue Aug 13, 2014 · 3 comments
Closed

Extend the listener mixin to provide "initial" data #44

spoike opened this issue Aug 13, 2014 · 3 comments
Milestone

Comments

@spoike
Copy link
Member

spoike commented Aug 13, 2014

Add the possibility to fetch initial data from a data store to a React component. This needs a change to the ListenerMixin's listenTo method and in the store implementation as well.

Motivating Example

var aStore = Reflux.createStore({
    init: function() {
        this.listenTo(anAction, function() {
            this.trigger('not initial data anymore');
        });
    }
    getInitialData: function() {
        return "the initial data";
         // is used by Listenermixin if a component wants initial data 
    }
});

var Component = React.createClass({
    mixins: [Reflux.ListenerMixin],
    getInitialState: function() {
        return {}; // <-- impossible to know the state if stores aren't initialized yet
    },
    componentDidMount: function() {
        this.listenTo(aStore, changeCallback, changeCallback);
            // will call changeCallback twice, during store change and 
            // when the store has initialized
            // third callback should be optional
    },
    changeCallback: function(data) {
        console.log(data);
        this.setState({
            data: data
        });
    }
});

In the example, before invoking the anAction the component should be able to set the state with "the initial data" fetched from the store's getInitialData method. When invoking the anAction the component should be able to set the state with "not initial data anymore" fetched from the change event.

Thoughts?

@KyleAMathews
Copy link
Contributor

Interesting. Could getInitialData return a promise? That might be useful for server fetching. Actions are "held" until the promise is returned.

@spoike
Copy link
Member Author

spoike commented Aug 15, 2014

Probably should rename it to get "default" data. The point is more or less how to handle initialization of components, well before data comes in.

@spoike spoike added this to the 0.1.7 milestone Aug 20, 2014
@spoike
Copy link
Member Author

spoike commented Aug 20, 2014

Closing issue as it is merged in #46 and #49

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

No branches or pull requests

2 participants