From 8219f30ed20a972caf5de14257ea915183f1f0c4 Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Fri, 28 Nov 2014 00:35:41 -0800 Subject: [PATCH] Gaurd against value already being observ. --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3c47a70..fc4b9c6 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,8 @@ function ObservVarhash (hash, createValue) { obs.delete = del.bind(obs) for (key in hash) { - obs[key] = createValue(hash[key], key) + obs[key] = typeof hash[key] === 'function' ? + hash[key] : createValue(hash[key], key) if (isFn(obs[key])) { obs._removeListeners[key] = obs[key](watch(obs, key, currentTransaction)) @@ -59,7 +60,8 @@ function get (key) { function put (createValue, key, val) { checkKey(key) - var observ = createValue(val, key) + var observ = typeof observ === 'function' ? + createValue(val, key) : val var state = extend(this()) state[key] = isFn(observ) ? observ() : observ @@ -145,7 +147,9 @@ function checkKey (key) { } // identify deletes -function Tombstone () {} +function Tombstone () { + +} Tombstone.prototype.toJSON = nameTombstone Tombstone.prototype.inspect = nameTombstone