diff --git a/WIP/test1.js b/WIP/test1.js deleted file mode 100644 index da3caf9..0000000 --- a/WIP/test1.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const Timer = require('./examples/Timer'); -const List = require('./src/list/List'); - -var run = () => { - var redis = require("redis"); - this.client1 = redis.createClient({ host: "localhost", port: 6379 }); - this.client2 = redis.createClient({ host: "localhost", port: 6379 }); - var hash = "ccc" - this.client1.subscribe(hash); - this.client1.subscribe(hash); - - - let listA = new List("A"); - let listB = new List("B"); - let listC = new List("C"); - - const handleMessage = (hash, event) => { - const l = List.fromJson(JSON.parse(event)); - // console.log("LIST", l); - - if(l.id === 'A') { - listB.join(l); - listC.join(l); - } else if(l.id === 'B') { - listA.join(l); - listC.join(l); - } else if(l.id === 'C') { - listA.join(l); - console.log("Items:", listA.items.length); - // console.log(JSON.stringify(listA, null, 1)); - } - - } - - this.client1.on("message", handleMessage); - this.client2.on("message", handleMessage); - - let h = 0; - setInterval(() => { - listC.add("C--"+h); - this.client2.publish(hash, JSON.stringify(listC.toJson())); - h++; - }, 1000); - - let i = 0; - setInterval(() => { - let a = 0; - for(let a = 0; a < 10; a ++) { - listB.add("B--"+(i+a)); - } - this.client2.publish(hash, JSON.stringify(listB.toJson())); - i++; - }, 20); - - let k = 0; - setInterval(() => { - listA.add("A--"+k); - k++; - listA.add("A--"+k); - k++; - listA.add("A--"+k); - k++; - this.client2.publish(hash, JSON.stringify(listA.toJson())); - }, 100); -}; - -run(); diff --git a/WIP/test2.js b/WIP/test2.js deleted file mode 100644 index 5bb9322..0000000 --- a/WIP/test2.js +++ /dev/null @@ -1,92 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const async = require('asyncawait/async'); -const await = require('asyncawait/await'); -const ipfsDaemon = require('orbit-common/lib/ipfs-daemon'); -const ipfsAPI = require('orbit-common/lib/ipfs-api-promised'); -const List = require('./src/list/OrbitList'); -const Timer = require('./examples/Timer'); - -const startIpfs = async (() => { - return new Promise(async((resolve, reject) => { - const ipfsd = await(ipfsDaemon()); - resolve(ipfsd.daemon); - })); -}); - -let ipfs; - -var run = async(() => { - ipfs = await(startIpfs()); - - var redis = require("redis"); - this.client1 = redis.createClient({ host: "localhost", port: 6379 }); - this.client2 = redis.createClient({ host: "localhost", port: 6379 }); - var hash = "ccc" - this.client1.subscribe(hash); - this.client1.subscribe(hash); - - - let listA = new List("A", ipfs); - let listB = new List("B", ipfs); - let listC = new List("C", ipfs); - - const handleMessage = async((hash, event) => { - // const l = List.fromJson(JSON.parse(event)); - console.log(">", event); - const l = await(List.fromIpfsHash(ipfs, event)); - // console.log("ITEMS RECEIVED", l.items.length); - - if(l.id === 'A') { - listB.join(l); - listC.join(l); - } else if(l.id === 'B') { - // listA.join(l); - // listC.join(l); - } else if(l.id === 'C') { - listB.join(l); - var timer = new Timer('a'); - listC.join(listB); - console.log("join took " + timer.stop(true) + " ms"); - console.log("Items:", listC.items.length); - // console.log(listC.toString()); - } - }); - - this.client1.on("message", handleMessage); - this.client2.on("message", handleMessage); - - let h = 0; - setInterval(async(() => { - listC.add("C--"+h); - const list = await(listC.getIpfsHash()); - this.client2.publish(hash, list); - h++; - }), 1000); - - let i = 0; - setInterval(async(() => { - let a = 0; - // for(let a = 0; a < 10; a ++) { - listB.add("B--"+(i+a)); - // } - const list = await(listB.getIpfsHash()); - this.client2.publish(hash, list); - i++; - }), 50); - -// let k = 0; -// setInterval(async(() => { -// listA.add("A--"+k); -// k++; -// listA.add("A--"+k); -// k++; -// listA.add("A--"+k); -// k++; -// this.client2.publish(hash, JSON.stringify(listA.toJson())); -// }), 100); -// }); -}); - -run(); diff --git a/src/list/Node.js b/src/list/Node.js index fca3850..6db8ddd 100644 --- a/src/list/Node.js +++ b/src/list/Node.js @@ -13,10 +13,6 @@ class Node { return "" + this.id + "." + this.seq + "." + this.ver; } - compact() { - return { id: this.id, seq: this.seq, ver: this.ver, data: this.data, next: this.next } - } - toJson() { return { id: this.id, seq: this.seq, ver: this.ver, data: this.data, next: this.next } } diff --git a/src/list/OrbitList.js b/src/list/OrbitList.js index 127a41d..6f78b74 100644 --- a/src/list/OrbitList.js +++ b/src/list/OrbitList.js @@ -27,7 +27,6 @@ class OrbitList extends List { node._commit(); this._currentBatch.push(node); this.ver ++; - } join(other) { diff --git a/src/list/OrbitNode.js b/src/list/OrbitNode.js index 619ea42..c5a848b 100644 --- a/src/list/OrbitNode.js +++ b/src/list/OrbitNode.js @@ -14,10 +14,6 @@ class OrbitNode extends Node { this.hash = hash ? hash : this.ipfsHash; } - get compactId() { - return "" + this.id + "." + this.seq + "." + this.ver; - } - get ipfsHash() { this._commit(); return this.hash; diff --git a/test/list-node-tests.js b/test/list-node-tests.js index f0ad641..da5703d 100644 --- a/test/list-node-tests.js +++ b/test/list-node-tests.js @@ -37,25 +37,4 @@ describe('Node', () => { }); }); - describe('compact', () => { - it('presents the node as a compacted object', (done) => { - const node1 = new Node('A', 0, 0, 'hello'); - const node2 = new Node('B', 0, 0, 'hello', [node1]); - const compacted1 = node1.compact(); - const compacted2 = node2.compact(); - - assert.notEqual(compacted1, null); - assert.equal(compacted1.id, 'A'); - assert.equal(compacted1.seq, 0); - assert.equal(compacted1.ver, 0); - assert.equal(compacted1.data, 'hello'); - assert.equal(compacted1.next instanceof Array, true); - assert.equal(compacted1.next.length, 0); - - assert.equal(compacted2.id, 'B'); - assert.equal(compacted2.next.length, 1); - assert.equal(compacted2.next[0], 'A.0.0'); - done(); - }); - }); });