From 76ce348a04b83693eda0e8a40f9888c1f5fe7ef5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 24 Jan 2017 19:47:00 -0800 Subject: obs-store - use published module --- app/scripts/lib/observable/host.js | 50 -------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 app/scripts/lib/observable/host.js (limited to 'app/scripts/lib/observable/host.js') diff --git a/app/scripts/lib/observable/host.js b/app/scripts/lib/observable/host.js deleted file mode 100644 index d1b110503..000000000 --- a/app/scripts/lib/observable/host.js +++ /dev/null @@ -1,50 +0,0 @@ -const Dnode = require('dnode') -const ObservableStore = require('./index') -const endOfStream = require('end-of-stream') - -// -// HostStore -// -// plays host to many RemoteStores and sends its state over a stream -// - -class HostStore extends ObservableStore { - - constructor (initState, opts) { - super(initState) - this._opts = opts || {} - } - - createStream () { - const self = this - // setup remotely exposed api - let remoteApi = {} - if (!self._opts.readOnly) { - remoteApi.put = (newState) => self.put(newState) - } - // listen for connection to remote - const dnode = Dnode(remoteApi) - dnode.on('remote', (remote) => { - // setup update subscription lifecycle - const updateHandler = (state) => remote.put(state) - self._onConnect(updateHandler) - endOfStream(dnode, () => self._onDisconnect(updateHandler)) - }) - return dnode - } - - _onConnect (updateHandler) { - // subscribe to updates - this.subscribe(updateHandler) - // send state immediately - updateHandler(this.get()) - } - - _onDisconnect (updateHandler) { - // unsubscribe to updates - this.unsubscribe(updateHandler) - } - -} - -module.exports = HostStore -- cgit