From 01bdf1a80fc82e1d507f923f009897fa733701a4 Mon Sep 17 00:00:00 2001 From: haad Date: Wed, 27 Apr 2016 09:21:04 +0200 Subject: [PATCH] Cleanup OperationsLog --- src/oplog/OperationsLog.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/oplog/OperationsLog.js b/src/oplog/OperationsLog.js index 721bc0d..af2b6e0 100644 --- a/src/oplog/OperationsLog.js +++ b/src/oplog/OperationsLog.js @@ -16,7 +16,8 @@ class OperationsLog { get ops() { return this._log.items.map((f) => { Object.assign(f.payload, { hash: f.hash }); - if(f.payload.key === null) Object.assign(f.payload, { key: f.hash }); + if(f.payload.key === null) + Object.assign(f.payload, { key: f.hash }); return f.payload; }); } @@ -41,15 +42,15 @@ class OperationsLog { } }; + let opHash, logHash; return this._log.add(entry) - .then((op) => { - return Log.getIpfsHash(this._ipfs, this._log).then((hash) => { - this._lastWrite = hash; - Cache.set(this.dbname, hash); - this.events.emit('data', this.dbname, hash); - return op.hash; - }); - }); + .then((op) => opHash = op.hash) + .then(() => Log.getIpfsHash(this._ipfs, this._log)) + .then((hash) => logHash = hash) + .then(() => this._lastWrite = logHash) + .then(() => Cache.set(this.dbname, logHash)) + .then(() => this.events.emit('data', this.dbname, logHash)) + .then(() => opHash) } merge(hash) {