aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/observable/host.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-25 11:47:00 +0800
committerkumavis <aaron@kumavis.me>2017-01-25 11:47:00 +0800
commit76ce348a04b83693eda0e8a40f9888c1f5fe7ef5 (patch)
treed31aeddd6752f03ca1c65569e4fadf203ca8692f /app/scripts/lib/observable/host.js
parenta06ee454045b9087160d3af1c081556662bbd3cb (diff)
downloadtangerine-wallet-browser-76ce348a04b83693eda0e8a40f9888c1f5fe7ef5.tar.gz
tangerine-wallet-browser-76ce348a04b83693eda0e8a40f9888c1f5fe7ef5.tar.zst
tangerine-wallet-browser-76ce348a04b83693eda0e8a40f9888c1f5fe7ef5.zip
obs-store - use published module
Diffstat (limited to 'app/scripts/lib/observable/host.js')
-rw-r--r--app/scripts/lib/observable/host.js50
1 files changed, 0 insertions, 50 deletions
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