Skip to content

Commit

Permalink
Merge pull request #3 from Raynos/patch-1
Browse files Browse the repository at this point in the history
Gaurd against value already being observ.
  • Loading branch information
nrw committed Nov 28, 2014
2 parents aa5f9a9 + 8219f30 commit c505264
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -145,7 +147,9 @@ function checkKey (key) {
}

// identify deletes
function Tombstone () {}
function Tombstone () {

}

Tombstone.prototype.toJSON = nameTombstone
Tombstone.prototype.inspect = nameTombstone
Expand Down

0 comments on commit c505264

Please sign in to comment.