Add 'load' and 'loaded' events for broadcasting load state

This commit is contained in:
haad
2016-03-21 14:25:05 +01:00
parent 50a2681421
commit e2e3374228
2 changed files with 27 additions and 10 deletions

View File

@@ -24,6 +24,8 @@ class Client {
await(this.db.use(channel, this.user, password));
this.db.events[channel].on('write', this._onWrite.bind(this));
this.db.events[channel].on('sync', this._onSync.bind(this));
this.db.events[channel].on('load', this._onLoad.bind(this));
this.db.events[channel].on('loaded', this._onLoaded.bind(this));
if(subscribe)
this._pubsub.subscribe(channel, password, async((channel, message) => this.db.sync(channel, message)));
@@ -58,6 +60,16 @@ class Client {
this.events.emit('data', channel, hash);
}
_onLoad(channel, hash) {
// console.log("LOAD!", channel, hash)
this.events.emit('load', channel, hash);
}
_onLoaded(channel, hash) {
// console.log("LOADED!", channel, hash)
this.events.emit('loaded', channel, hash);
}
_iterator(channel, password, options) {
const messages = this.db.query(channel, password, options);
let currentIndex = 0;