From 491b578490c225b14cfb1d316e86d2a004ca4dbc Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 11 Mar 2016 14:11:17 +0100 Subject: [PATCH] Fix hasChild of Node and OrbitNode --- src/list/Node.js | 18 +++++++++--------- src/list/OrbitNode.js | 9 +++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/list/Node.js b/src/list/Node.js index c561ce9..0debc74 100644 --- a/src/list/Node.js +++ b/src/list/Node.js @@ -9,6 +9,15 @@ class Node { this.next = next ? next.map((f) => f.compactId ? f.compactId : f) : []; } + hasChild(a) { + const id = a.compactId; + for(let i = 0; i < this.next.length; i++) { + if(this.next[i] === id) + return true; + } + return false; + } + get compactId() { return "" + this.id + "." + this.seq + "." + this.ver; } @@ -24,15 +33,6 @@ class Node { static equals(a, b) { return a.id === b.id && a.seq === b.seq && a.ver === b.ver; } - - hasChild(a) { - const id = a.compactId; - for(let i = 0; i < this.next.length; i++) { - if(this.next[i] === id) - return true; - } - return false; - } } module.exports = Node; diff --git a/src/list/OrbitNode.js b/src/list/OrbitNode.js index 4388dc8..f584fa7 100644 --- a/src/list/OrbitNode.js +++ b/src/list/OrbitNode.js @@ -30,6 +30,15 @@ class OrbitNode extends Node { })); } + hasChild(a) { + const id = a.compactId; + for(let i = 0; i < this.next.length; i++) { + if(this.next[i].compactId === id) + return true; + } + return false; + } + _commit() { if(!this.hash) { const r = await(ipfsAPI.putObject(this._ipfs, JSON.stringify(this.asJson)));