From 7f34829645192ea8013cdffe4de3b585cbcb6f2f Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 26 Feb 2016 13:45:57 +0100 Subject: [PATCH] Cleanups --- examples/keyvalueReader.js | 47 +++++++++++++++++--------------------- examples/reader.js | 2 -- src/OrbitClient.js | 2 -- src/PubSub.js | 1 - src/list/OrbitList.js | 1 - test/orbit-client-tests.js | 18 --------------- 6 files changed, 21 insertions(+), 50 deletions(-) diff --git a/examples/keyvalueReader.js b/examples/keyvalueReader.js index d71ba8b..8aa724f 100644 --- a/examples/keyvalueReader.js +++ b/examples/keyvalueReader.js @@ -12,37 +12,32 @@ const port = 3333; const username = process.argv[3] ? process.argv[3] : 'LambOfGod'; const password = ''; -let running = false; let run = (async(() => { - if(!running) { - try { - running = true; - const orbit = OrbitClient.connect(host, port, username, password); - const channel = process.argv[2] ? process.argv[2] : 'testing123'; - const db = orbit.channel(channel); + try { + const orbit = OrbitClient.connect(host, port, username, password); + const channel = process.argv[2] ? process.argv[2] : 'testing123'; + const db = orbit.channel(channel); - let count = 1; + let count = 1; - setInterval(async(() => { - const key = process.argv[4] ? process.argv[4] : 'greeting'; - let timer = new Timer(true); - let v = db.get(key); + setInterval(async(() => { + const key = process.argv[4] ? process.argv[4] : 'greeting'; + let timer = new Timer(true); + let v = db.get(key); - console.log("---------------------------------------------------") - console.log("Key | Value") - console.log("---------------------------------------------------") - console.log(`${key} | ${v}`); - console.log("---------------------------------------------------") - console.log(`Query #${count} took ${timer.stop(true)} ms\n`); + console.log("---------------------------------------------------") + console.log("Key | Value") + console.log("---------------------------------------------------") + console.log(`${key} | ${v}`); + console.log("---------------------------------------------------") + console.log(`Query #${count} took ${timer.stop(true)} ms\n`); - count ++; - running = false; - }), 1000); - } catch(e) { - console.error("error:", e); - console.error(e.stack); - process.exit(1); - } + count ++; + }), 1000); + } catch(e) { + console.error("error:", e); + console.error(e.stack); + process.exit(1); } }))(); diff --git a/examples/reader.js b/examples/reader.js index 7b64374..b25d5ec 100644 --- a/examples/reader.js +++ b/examples/reader.js @@ -33,14 +33,12 @@ let run = (async(() => { console.log(`Query #${count} took ${timer.stop(true)} ms\n`); let timer2 = new Timer(true); - // const c = channel.iterator({ limit: -1 }).collect().length; let items = channel.iterator({ limit: 10 }).collect(); console.log("---------------------------------------------------") console.log("Key | Value") console.log("---------------------------------------------------") console.log(items.map((e) => `${e.payload.key} | ${e.payload.value}`).join("\n")); console.log("---------------------------------------------------") - // console.log(`Found ${items.length} items from ${c}\n`); console.log(`Query 2 #${count} took ${timer2.stop(true)} ms\n`); running = false; diff --git a/src/OrbitClient.js b/src/OrbitClient.js index bfea6cd..d715822 100644 --- a/src/OrbitClient.js +++ b/src/OrbitClient.js @@ -15,8 +15,6 @@ const PubSub = require('./PubSub'); const List = require('./list/OrbitList'); const DataStore = require('./DataStore'); -var Timer = require('../examples/Timer'); - const pubkey = Keystore.getKeys().publicKey; const privkey = Keystore.getKeys().privateKey; diff --git a/src/PubSub.js b/src/PubSub.js index 7cad6d0..6abf00f 100644 --- a/src/PubSub.js +++ b/src/PubSub.js @@ -10,7 +10,6 @@ class Pubsub { this._socket = io(`http://${host}:${port}`); this._socket.on('connect', (socket) => console.log(`Connected to http://${host}:${port}`)); this._socket.on('disconnect', (socket) => console.log(`Disconnected from http://${host}:${port}`)); - this._socket.on('event', (e) => console.log('Event:', e)); this._socket.on('error', (e) => console.log('error:', e)); this._socket.on('message', this._handleMessage.bind(this)); this._socket.on('latest', (hash, message) => { diff --git a/src/list/OrbitList.js b/src/list/OrbitList.js index 31b1a0f..127a41d 100644 --- a/src/list/OrbitList.js +++ b/src/list/OrbitList.js @@ -35,7 +35,6 @@ class OrbitList extends List { // WIP: fetch missing nodes let depth = 0; - const isReferenced = (all, item) => _.findLast(all, (f) => f === item) !== undefined; const fetchRecursive = (hash) => { hash = hash instanceof Node === true ? hash.hash : hash; diff --git a/test/orbit-client-tests.js b/test/orbit-client-tests.js index 35b4562..d3b3fc4 100644 --- a/test/orbit-client-tests.js +++ b/test/orbit-client-tests.js @@ -30,24 +30,6 @@ describe('Orbit Client', () => { done(); })); -/* - describe('Info', function() { // } - // }; - // var res = db.setMode(mode) - // var info = orbit.channel(channel, 'password').info(); - // assert.notEqual(info, null); - // assert.equal(info.head, null); - // assert.equal(JSON.stringify(info.modes), JSON.stringify(res)); - // orbit.channel(channel, 'password').delete(); - // } catch(e) { - // orbit.channel(channel, 'password').delete(); - // assert.equal(e, null); - // } - // done(); - // })); - }); -*/ - describe('Add events', function() { it('adds an item to an empty channel', async((done) => { const head = db.add('hello');