Skip to content

Commit

Permalink
emit only once in object.$add
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 28, 2014
1 parent c941fd6 commit bab4829
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ var ObjProxy = Object.create(Object.prototype)
def(ObjProxy, '$add', function (key, val) {
if (hasOwn.call(this, key)) return
this[key] = val
convertKey(this, key)
// emit a propagating set event
this.__emitter__.emit('set', key, val, true)
convertKey(this, key, true)
}, !hasProto)

def(ObjProxy, '$delete', function (key) {
Expand Down Expand Up @@ -235,7 +233,7 @@ function watchArray (arr) {
* so it emits get/set events.
* Then watch the value itself.
*/
function convertKey (obj, key) {
function convertKey (obj, key, propagate) {
var keyPrefix = key.charAt(0)
if (keyPrefix === '$' || keyPrefix === '_') {
return
Expand All @@ -246,7 +244,7 @@ function convertKey (obj, key) {
var emitter = obj.__emitter__,
values = emitter.values

init(obj[key])
init(obj[key], propagate)

oDef(obj, key, {
enumerable: true,
Expand Down

0 comments on commit bab4829

Please sign in to comment.