mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-27 16:32:30 +00:00
Move load status to init
This commit is contained in:
parent
76a0ad5d52
commit
0509b6ee5d
@ -22,28 +22,26 @@ class OrbitDB {
|
|||||||
this._logs[channel] = await(Log.create(this._ipfs, this.user.username));
|
this._logs[channel] = await(Log.create(this._ipfs, this.user.username));
|
||||||
this.events[channel] = new EventEmitter();
|
this.events[channel] = new EventEmitter();
|
||||||
|
|
||||||
|
this.events[channel].emit('load', channel);
|
||||||
Cache.loadCache();
|
Cache.loadCache();
|
||||||
this.sync(channel, Cache.get(channel));
|
this.sync(channel, Cache.get(channel));
|
||||||
|
this.events[channel].emit('loaded', channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
sync(channel, hash) {
|
sync(channel, hash) {
|
||||||
this.events[channel].emit('load', channel, hash);
|
// console.log("--> Head:", hash)
|
||||||
// setTimeout(async(() => {
|
if(hash && this._logs[channel]) {
|
||||||
// console.log("--> Head:", hash)
|
const oldCount = this._logs[channel].items.length;
|
||||||
if(hash && this._logs[channel]) {
|
const other = await(Log.fromIpfsHash(this._ipfs, hash));
|
||||||
const oldCount = this._logs[channel].items.length;
|
await(this._logs[channel].join(other));
|
||||||
const other = await(Log.fromIpfsHash(this._ipfs, hash));
|
|
||||||
await(this._logs[channel].join(other));
|
|
||||||
|
|
||||||
// Only emit the event if something was added
|
// Only emit the event if something was added
|
||||||
const joinedCount = (this._logs[channel].items.length - oldCount);
|
const joinedCount = (this._logs[channel].items.length - oldCount);
|
||||||
if(joinedCount > 0) {
|
if(joinedCount > 0) {
|
||||||
this.events[channel].emit('sync', channel, hash);
|
this.events[channel].emit('sync', channel, hash);
|
||||||
Cache.set(channel, hash);
|
Cache.set(channel, hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.events[channel].emit('loaded', channel, hash);
|
}
|
||||||
// }), 3000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DB Operations */
|
/* DB Operations */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user