Fix hasChild of Node and OrbitNode

This commit is contained in:
haad 2016-03-11 14:11:17 +01:00
parent f258a53bd7
commit 491b578490
2 changed files with 18 additions and 9 deletions

View File

@ -9,6 +9,15 @@ class Node {
this.next = next ? next.map((f) => f.compactId ? f.compactId : f) : []; 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() { get compactId() {
return "" + this.id + "." + this.seq + "." + this.ver; return "" + this.id + "." + this.seq + "." + this.ver;
} }
@ -24,15 +33,6 @@ class Node {
static equals(a, b) { static equals(a, b) {
return a.id === b.id && a.seq === b.seq && a.ver === b.ver; 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; module.exports = Node;

View File

@ -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() { _commit() {
if(!this.hash) { if(!this.hash) {
const r = await(ipfsAPI.putObject(this._ipfs, JSON.stringify(this.asJson))); const r = await(ipfsAPI.putObject(this._ipfs, JSON.stringify(this.asJson)));