diff options
Diffstat (limited to 'app/scripts/lib/observable/index.js')
-rw-r--r-- | app/scripts/lib/observable/index.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/scripts/lib/observable/index.js b/app/scripts/lib/observable/index.js new file mode 100644 index 000000000..d193e5554 --- /dev/null +++ b/app/scripts/lib/observable/index.js @@ -0,0 +1,33 @@ +const EventEmitter = require('events').EventEmitter + +class ObservableStore extends EventEmitter { + + constructor (initialState) { + super() + this._state = initialState + } + + get () { + return this._state + } + + put (newState) { + this._put(newState) + } + + subscribe (handler) { + this.on('update', handler) + } + + unsubscribe (handler) { + this.removeListener('update', handler) + } + + _put (newState) { + this._state = newState + this.emit('update', newState) + } + +} + +module.exports = ObservableStore |