ampersand-state
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -30,2 +30,3 @@ 'use strict'; | ||
this._values = {}; | ||
this._eventBubblingHandlerCache = {}; | ||
this._definition = Object.create(this._definition); | ||
@@ -501,3 +502,3 @@ if (options.parse) attrs = this.parse(attrs, options); | ||
this._safeSet(child, new this._children[child]({}, {parent: this})); | ||
this.listenTo(this[child], 'all', this._getEventBubblingHandler(child)); | ||
this.listenTo(this[child], 'all', this._getCachedEventBubblingHandler(child)); | ||
} | ||
@@ -508,10 +509,13 @@ }, | ||
// adding a name to the change string. | ||
_getEventBubblingHandler: function (propertyName) { | ||
return bind(function (name, model, newValue) { | ||
if (changeRE.test(name)) { | ||
this.trigger('change:' + propertyName + '.' + name.split(':')[1], model, newValue); | ||
} else if (name === 'change') { | ||
this.trigger('change', this); | ||
} | ||
}, this); | ||
_getCachedEventBubblingHandler: function (propertyName) { | ||
if (!this._eventBubblingHandlerCache[propertyName]) { | ||
this._eventBubblingHandlerCache[propertyName] = bind(function (name, model, newValue) { | ||
if (changeRE.test(name)) { | ||
this.trigger('change:' + propertyName + '.' + name.split(':')[1], model, newValue); | ||
} else if (name === 'change') { | ||
this.trigger('change', this); | ||
} | ||
}, this); | ||
} | ||
return this._eventBubblingHandlerCache[propertyName]; | ||
}, | ||
@@ -762,7 +766,7 @@ | ||
if (previousVal) { | ||
this.stopListening(previousVal); | ||
this.stopListening(previousVal, 'all', this._getCachedEventBubblingHandler(attributeName)); | ||
} | ||
if (newVal != null) { | ||
this.listenTo(newVal, 'all', this._getEventBubblingHandler(attributeName)); | ||
this.listenTo(newVal, 'all', this._getCachedEventBubblingHandler(attributeName)); | ||
} | ||
@@ -769,0 +773,0 @@ } |
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -542,3 +542,3 @@ # ampersand-state | ||
var Person = AmpersandState.extend({ | ||
var Person = State.extend({ | ||
props: { | ||
@@ -545,0 +545,0 @@ name: 'string' |
67002
766