This commit is contained in:
haad 2016-03-06 10:17:03 +01:00
parent 7d7a2df631
commit 34ae809b0c
3 changed files with 8 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}
}