Last active
December 6, 2015 19:18
-
-
Save ikouchiha47/d6349b283bde8a42b97e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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