Skip to content

Commit

Permalink
parsing subs as specced for state v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim de Beer committed May 22, 2016
1 parent 0189f6c commit 22801ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/sync/subscription/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

const isFn = /^\$fn-/
module.exports = function (subs) {
subs = parse(subs)
return subs
Expand All @@ -8,11 +8,12 @@ module.exports = function (subs) {
function parse (obj) {
const result = {}
for (let i in obj) {
if (/^\$fn-/.test(i)) {
if (isFn.test(i)) {
let val = obj[i]
i = i.slice(4)
// need to fix babel stuff in these parses
obj[i] = new Function('return ' + val)() //eslint-disable-line
// a posbility is to add some extra arguments
obj[i] = new Function('return ' + val)() // eslint-disable-line
}
if (i === 'val' || i === 'done') {
result[i] = obj[i]
Expand Down
10 changes: 2 additions & 8 deletions lib/sync/subscription/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = function serializeSubscription (state, subs) {
if ('client' in subs) {
let hub = state.getRoot()
if (hub === state) {
console.log('special handle for client')
subs.clients = { [hub.id]: subs.client }
delete subs.client
}
Expand All @@ -18,15 +17,10 @@ function parse (obj, last) {
const result = {}
for (let i in obj) {
if (i !== '_') {
// also check for field 'map'
if (i === 'map' && typeof obj[i] === 'function') {
if (i === 'exec' && typeof obj[i] === 'function') {
result['$fn-' + i] = obj[i].toString()
} else if (i === 'val' || i === 'done') {
if (typeof obj[i] === 'function') {
result['$fn-' + i] = obj[i].toString()
} else {
result[i] = obj[i]
}
result[i] = obj[i]
} else {
result[i] = parse(obj[i])
}
Expand Down

0 comments on commit 22801ba

Please sign in to comment.