import Reflux from 'reflux';
import StateMixin from 'reflux-state-mixin';
import PreferencesActions from 'actions';
import { Preferences } from 'models';
/**
* Preferences store.
*/
const PreferencesStore = Reflux.createStore({
/**
* adds a state to the store, similar to React.Component's state
* @see https://github.com/yonatanmn/Super-Simple-Flux#reflux-state-mixin
*
* If you call `this.setState({...})` this will cause the store to trigger
* and push down its state as props to connected components.
*/
mixins: [StateMixin.store],
/**
* listen to all actions defined in ../actions/index.jsx
*/
listenables: PreferencesActions,
/**
* When the application is connected we can fetch the app preferences.
*/
onConnected() {
this.state.preferences.fetch({
success: () => {
this.trigger(this.state);
}
});
},
/**
* Initialize the Preferences store state. The returned object must
* contain all keys that you might want to modify with this.setState().
*
* @return {Object} initial store state.
*/
getInitialState() {
return {
preferences: new Preferences()
};
}
});
export default PreferencesStore;
export { PreferencesStore };
|