Skip to content

Instantly share code, notes, and snippets.

@ikouchiha47
Last active December 6, 2015 19:18
Show Gist options
  • Save ikouchiha47/d6349b283bde8a42b97e to your computer and use it in GitHub Desktop.
Save ikouchiha47/d6349b283bde8a42b97e to your computer and use it in GitHub Desktop.
"use strict";
import Fluxible from 'fluxible';
import {createStore} from 'fluxible/addons';
const tickAction = (actionCtx, payload) => {
actionCtx.dispatch('COUNT_ACTION', payload)
};
const TickStore = createStore({
storeName: 'TickStore',
handlers: {
COUNT_ACTION: 'tickHandler'
},
initialize: function() {
this.counter = 0;
},
tickHandler: function(payload) {
this.counter = payload;
this.emitChange();
},
getCounter: function() {
return this.counter;
},
dehydrate: function () {
return {
counter: this.counter
}
},
rehydrate: function(state) {
this.counter = state.counter;
}
});
const fApp = new Fluxible({
stores: [TickStore]
});
const context = fApp.createContext();
var s = context.getStore(TickStore);
context.executeAction(tickAction, 1);
console.log(s.getCounter());
context.executeAction(tickAction, 2);
// er.. ok, that works, but I wouldn't do setTimeout everytiem , would I?
setTimeout(() => {
console.log(s.getCounter());
}, 2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment