spoike/refluxjs — pull request #46 by SimonDegraeve (2014-08-17 06:48:24+00:00)
Title: Add getInititalData() to Store

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:

```javascript
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