diff --git a/src/OrbitClient.js b/src/OrbitClient.js index 4bd9de3..11c7fce 100644 --- a/src/OrbitClient.js +++ b/src/OrbitClient.js @@ -22,7 +22,7 @@ class OrbitClient { if(subscribe === undefined) subscribe = true; this.db.use(channel, this.user, password); - this.db.events.on('data', (hash) => this._pubsub.publish(channel, hash)); + this.db.events.on('write', this._onUpdated.bind(this)); if(subscribe) this._pubsub.subscribe(channel, password, async((channel, message) => this.db.sync(channel, message))); @@ -48,6 +48,11 @@ class OrbitClient { this.network = null; } + _onUpdated(channel, hash) { + this._pubsub.publish(channel, hash) + this.events.emit('data', channel, hash); + } + _iterator(channel, password, options) { const messages = this.db.query(channel, password, options); let currentIndex = 0; diff --git a/src/OrbitDB.js b/src/OrbitDB.js index 7c917ae..077e582 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -4,7 +4,6 @@ const Lazy = require('lazy.js'); const EventEmitter = require('events').EventEmitter; const async = require('asyncawait/async'); const await = require('asyncawait/await'); -const ipfsAPI = require('orbit-common/lib/ipfs-api-promised'); const OrbitList = require('./list/OrbitList'); const Operation = require('./db/Operation'); const OpTypes = require('./db/OpTypes'); @@ -106,7 +105,7 @@ class OrbitDB { // Write an op to the db _write(channel, password, operation, key, value, data) { const hash = await(Operation.create(this._ipfs, this._logs[channel], this.user, operation, key, value)); - this.events.emit('data', hash); + this.events.emit('write', channel, hash); return key; } } diff --git a/src/PubSub.js b/src/PubSub.js index f0e61a1..6f8c19b 100644 --- a/src/PubSub.js +++ b/src/PubSub.js @@ -1,6 +1,6 @@ 'use strict'; -const io = require('socket.io-client'); +const io = require('socket.io-client'); class Pubsub { constructor(ipfs) {