Skip to content

Commit

Permalink
removed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim de Beer committed Aug 25, 2016
1 parent 0d369fb commit a3d65c7
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 64 deletions.
7 changes: 4 additions & 3 deletions h.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
// not really nice maybe remove this for hub and state
var Hub = require('./')
const Hub = require('./')
module.exports = function (val, stamp) {
return new Hub(val, stamp)
// what about allowing objects for stamp that have type, src
// val then calling vstamp in these functions? makes it super easy
return new Hub(val, stamp || false)
}
3 changes: 1 addition & 2 deletions lib/client/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports.define = {
// check if its an upstream send -- not !subs
if (!subs || subs.val === true) {
const id = this.id.compute()
console.log('send it', id, this.root.id, state.path())
// this is where you repair offsets
serialize(send(this, stamp, id), state, type, stamp, subs, tree, sType, id)
}
Expand Down Expand Up @@ -90,6 +89,6 @@ function socketSend (client, inprogress, id) {
payload.client = inprogress[id].client
delete inprogress[id].client
}
console.log(' go send out!', id, client.root.id, payload)
// console.log(' go send out!', id, client.root.id, payload)
client.socket.send(JSON.stringify(payload))
}
1 change: 0 additions & 1 deletion lib/downstream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports.properties = {
exports.on = {
remove: {
port () {
// multiple servers for different contexts... be carefull but could be possible
if (this.hasOwnProperty('port')) {
this.port.set(null)
}
Expand Down
1 change: 0 additions & 1 deletion lib/downstream/server/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function closeConnections (hub) {
const id = hub.id
clients.each((client) => {
if (client.upstream && client.upstream.compute() === id) {
console.log('!@!@#?')
client.socket.close()
}
})
Expand Down
2 changes: 1 addition & 1 deletion lib/downstream/server/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function createServer (hub, port) {
offset(data, socket)
return
}
console.log('DOWN-INCOMING:', socket.client && socket.client.id.compute(), JSON.stringify(data, false, 2))
// console.log('DOWN-INCOMING:', socket.client && socket.client.id.compute(), JSON.stringify(data, false, 2))
if (!data.client && !socket.client) {
console.log('WRONG!')
}
Expand Down
3 changes: 0 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ module.exports = new Sync({
syncUp: false,
syncDown: false,
on: {
data (val) {
console.log('???', val, this.id)
},
error (err) {
console.log(err)
}
Expand Down
3 changes: 0 additions & 3 deletions lib/offset/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports.incoming = function offsetClient (hub, socket, data, clocksy) {
}
socket.offset = tDelta
const stamp = vstamp.create('connect')
// very bad spot for this...
hub.set({ connected: true }, stamp)
vstamp.close(stamp)
} else {
Expand All @@ -24,5 +23,3 @@ exports.incoming = function offsetClient (hub, socket, data, clocksy) {
vstamp.offset = Math.abs(tDelta) > 10 ? tDelta : 0
}
}

// resolve clocks
4 changes: 2 additions & 2 deletions lib/serialize/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const merge = require('lodash.merge')
const merge = require('lodash.merge') // use a simple merge
// general purpose for upstream as well -- really is the best

module.exports = function serialize (data, state, type, stamp, subs, tree, sType, id) {
Expand All @@ -18,7 +18,7 @@ module.exports = function serialize (data, state, type, stamp, subs, tree, sType
select.stamp = state.stamp
} else {
if (state.val && state.val.isBase) {
console.log('got a ref right hur', state.path(), state.val.path(), state.stamp)
// console.log('got a ref right hur', state.path(), state.val.path(), state.stamp)
select.val = '$root.' + state.val.realPath(false, true).join('.')
serialize(data, state.val, type, stamp, subs, tree, sType, id)
} else if (state.val !== void 0) { select.val = state.val }
Expand Down
6 changes: 1 addition & 5 deletions lib/sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ module.exports = new State({
}
this.stamp = stamp
} else if (!src) {
// creation of stamp
// console.log('add stamp stuff!')
stamp = vstamp.setSrc(stamp, hub.id)
this.stamp = stamp
if (this.syncUp && hub.client) {
const client = hub.client.origin()
// remove the parity with subs
if(hub.client.val) { client.send(this, void 0, stamp) }
// vstamp.on(originalStamp, () => vstamp.close(stamp))
if (hub.client.val) { client.send(this, void 0, stamp) }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sync/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.define = {
if (stamp && this.tombstones && this.tombstones[key]) {
const p = vstamp.parse(stamp)
// do some offset right hur
if (Number(p.val) - 1e3 < Number(vstamp.parse(this.tombstones[key]).val)) {
if (Number(p.val) - 1e3 < Number(vstamp.val(this.tombstones[key]))) {
console.log('TOMBSTONE ---> !!!!!', key)
return
}
Expand Down
29 changes: 1 addition & 28 deletions lib/sync/set.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,32 @@
'use stirct'
const vstamp = require('vigour-stamp')
const isObj = require('vigour-util/is/obj')
// const slist = {}

// allways need spawn stamp for this, something like spawned from or something...
exports.define = {
extend: {
set (set, val, stamp, nocontext, isNew) {
// var created
const slist = this.root.loop
// console.logx/(slist)

const obj = isObj(val)
if (obj) {
if (val.stamp) {
stamp = val.stamp

if (!slist[stamp]) {
slist[stamp] = true
// created = true
}
}
}
if (stamp && this.stamp) {
if (Number(vstamp.val(stamp)) < Number(vstamp.val(this.stamp))) {
if (!obj) {
// logmismatch(this, val, stamp)
return
} else if (val.val) {
// logmismatch(this, val, stamp)
delete val.val
}
}
}
// console.log(this.path())
const changed = set.call(this, val, stamp, nocontext, isNew)
// if (created) {
// way too heavy ofc
// process.nextTick(() => {
// vstamp.close(stamp)
// delete slist[stamp]
// })
// }
return changed
}
},
isSync: { value: true }
isSync: true
}

// function logmismatch (t, val, stamp) {
// console.log(
// 'STAMP-MISMATCH: ', t.getRoot().id, t.path(),
// '\n current:', t.val,
// '\n new:', val,
// '\n new-stamp:', stamp,
// '\n current-stamp:', t.stamp
// )
// }
1 change: 0 additions & 1 deletion lib/sync/sync.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'
// need to use a function for sync -- in the funciton will recieve true if up or somethign
// addhere to play state content api -- add down / up

exports.properties = {
syncUp: true,
syncDown: true,
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
require('./queue')
require('./clients')
// require('./clients')
// require('./context')

/*
Expand Down
12 changes: 0 additions & 12 deletions test/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ test('queue', function (t) {
id: 1,
url: 'ws://localhost:6000',
context: 'blurf'

})

client1.subscribe(subs)
Expand Down Expand Up @@ -68,7 +67,6 @@ test('queue', function (t) {
setTimeout(() => {
client1.a.set('a')
isConnected(true, reconnect)
// client1.c.remove() -- not supported yet need tombstones
server.port.set(6000)
}, 50)
}, 50)
Expand All @@ -91,8 +89,6 @@ test('queue', function (t) {
context.c.is(null),
client2.c.is(null)
]).then(() => {
console.log('fuck waht?')

t.equal(context.a.val, 'a', 'server - "a" is set to client1')
t.equal(context.b.val, -2, 'server - "b" is set to client2')
t.equal(context.c, null, 'server - "c" is removed')
Expand All @@ -104,22 +100,14 @@ test('queue', function (t) {
t.equal(client2.c, null, 'client2 - "c" is removed')
t.equal(client1.reference.val, client1.a, 'client1 has reference')
t.equal(client2.reference.val, client2.a, 'client2 has reference')

// --- fuck!!!
console.log(client2.special.a)
t.equal(context.special.a.val, 'a', 'server recieved update on a')
t.equal(client2.special.a.val, 'a', 'client2 recieved update on a')
const parsed = vstamp.parse(stamp)
const result = vstamp.create(parsed.type, 1, parsed.val)
t.equal(context.special.a.stamp, result, 'server recieved correct stamp on a')
// --- wrong
t.equal(client2.special.a.stamp, result, 'client2 recieved correct stamp on a')
console.log('XXXXXXXXX')
server.remove()

console.log('remove dat clients')
client2.remove()
console.log('next')
client1.remove()
t.end()
}).catch((err) => {
Expand Down

0 comments on commit a3d65c7

Please sign in to comment.