diff --git a/lib/key_sync.js b/lib/key_sync.js index 508749b..8319dc2 100644 --- a/lib/key_sync.js +++ b/lib/key_sync.js @@ -103,16 +103,6 @@ KeySync.prototype.$$handleUpdate = function(value, context) { value = normalize(_.cloneDeep(value), context); - if (context.command === 'SET' && targetKey === context.currentKey) { - self.$timeout(function() { - _.each(self.$$model, function(value, key, model) { - if (_.first(key) !== '$') { - delete model[key]; - } - }); - }); - } - if (context.command === 'SET' && targetKey !== context.currentKey) { // Determine the relative path between the key we are listening too and the // origin of the event. @@ -151,8 +141,19 @@ KeySync.prototype.$$handleUpdate = function(value, context) { } self.$timeout(function() { + if (context.command === 'SET' && targetKey === context.currentKey) { + _.each(self.$$model, function(value, key, model) { + if (_.first(key) !== '$') { + delete model[key]; + } + }); + } + _.merge(self.$$model, value); - delete self.$$model.$value; + + if (self.$$model.$value) { + delete self.$$model.$value; + } }); };