habitrpg-shared: bug fixes on hydrate()

This commit is contained in:
Tyler Renelle 2013-05-22 13:57:10 +01:00
parent 258cf55abb
commit 77e37804e8
2 changed files with 6 additions and 4 deletions

View file

@ -6,9 +6,11 @@ helpers = require('habitrpg-shared/script/helpers')
###
Make sure model.get() returns all properties, see https://github.com/codeparty/racer/issues/116
###
module.exports.hydrate = hydrate = (spec, hydrated={}) ->
if _.isPlainObject(spec)
hydrated[k] = hydrate(v, hydrated[k]) for k,v of spec
module.exports.hydrate = hydrate = (spec) ->
if _.isObject(spec) and !_.isArray(spec)
hydrated = {}
keys = _.keys(spec).concat(_.keys(spec.__proto__))
keys.forEach (k) -> hydrated[k] = hydrate(spec[k])
hydrated
else spec

View file

@ -19,7 +19,7 @@ module.exports.app = (appExports, model) ->
perform the updates while tracking paths, then all the values at those paths
###
score = (taskId, direction) ->
# return setTimeout( (-> score(taskId, direction)), 500) if model._txnQueue.length > 0
#return setTimeout( (-> score(taskId, direction)), 500) if model._txnQueue.length > 0
uObj = misc.hydrate(user.get()) # see https://github.com/codeparty/racer/issues/116
tObj = uObj.tasks[taskId]