change-emitter
Listen for changes. Like an event emitter that only emits a single event type. Really tiny.
I extracted this from Redux's createStore()
because I found it to be useful in other contexts. Use it where you want the most minimal event subscription implementation possible.
Usage
const emitter = // Called `listen` instead of `subscribe` to avoid confusion with observable specconst unlisten = emitter emitter // logs `[1, 2, 3]`emitter // doesn't log
Larger example
Here's a (partial) implementation of Redux's createStore
:
const createStore = { let state = initialState const emitter = { state = emitter return action } { return state } return dispatch getState subscribe: emitterlisten }