Created
September 23, 2017 14:24
-
-
Save mugi-uno/e4589a03609a3e4163a8c6ea9148c8cc to your computer and use it in GitHub Desktop.
light_flux
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
import { EventEmitter } from 'events'; | |
import _ from 'lodash'; | |
export const emitter = new EventEmitter(); | |
export const createStore = (updater) => { | |
let store = {}; | |
emitter.on('pub', (...args) => { | |
const beforeStore = store; | |
store = updater(store, ...args); | |
if (!_.isEqual(beforeStore, store)) { | |
console.log('[store updated / before]', beforeStore); | |
console.log('[store updated / after]', store); | |
emitter.emit('sub', store, beforeStore); | |
} | |
}); | |
emitter.on('force', () => { | |
emitter.emit('sub', store, store); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment