BaseStore #
import BaseStore from 'fluxible/addons/BaseStore';
A base class that you can extend to reduce boilerplate when creating stores.
Built-In Methods #
emitChange()
- emits a 'change' eventgetContext()
- returns the store contextaddChangeListener(callback)
- simple method to add a change listenerremoveChangeListener(callback)
- removes a change listenershouldDehydrate()
- default implementation that returns true if achange
event has been emitted
Example #
class ApplicationStore extends BaseStore {
constructor (dispatcher) {
super(dispatcher);
this.currentPageName = null;
}
handleReceivePage (payload) {
this.currentPageName = payload.pageName;
this.emitChange();
}
getCurrentPageName () {
return this.currentPageName;
}
// For sending state to the client
dehydrate () {
return {
currentPageName: this.currentPageName
};
}
// For rehydrating server state
rehydrate (state) {
this.currentPageName = state.currentPageName;
}
}
ApplicationStore.storeName = 'ApplicationStore';
ApplicationStore.handlers = {
'RECEIVE_PAGE': 'handleReceivePage'
};
export default ApplicationStore;