Permalink
Browse files

Do not redispatch active properties

  • Loading branch information...
1 parent 36bd20f commit 38d6540bb64586e3e8f443cf6e879727124de31f @kriskowal committed Dec 12, 2012
Showing with 19 additions and 12 deletions.
  1. +18 −12 listen/property-changes.js
  2. +1 −0 spec/listen/property-changes-spec.js
View
@@ -144,6 +144,11 @@ PropertyChanges.prototype.removeBeforeOwnPropertyChangeListener = function (key,
PropertyChanges.prototype.dispatchOwnPropertyChange = function (key, value, beforeChange) {
var descriptor = PropertyChanges.getOwnPropertyChangeDescriptor(this, key);
+ if (descriptor.isActive) {
+ return;
+ }
+ descriptor.isActive = true;
+
var listeners;
if (beforeChange) {
listeners = descriptor.willChangeListeners;
@@ -157,19 +162,20 @@ PropertyChanges.prototype.dispatchOwnPropertyChange = function (key, value, befo
propertyName = propertyName && propertyName[0].toUpperCase() + propertyName.slice(1);
var specificHandlerName = "handle" + propertyName + changeName;
- // dispatch to each listener
- listeners.forEach(function (listener) {
- var thisp = listener;
- listener = (
- listener[specificHandlerName] ||
- listener[genericHandlerName] ||
- // TODO: handleEvent(event)
- listener
- );
- if (listener.call) {
+ try {
+ // dispatch to each listener
+ listeners.forEach(function (listener) {
+ var thisp = listener;
+ listener = (
+ listener[specificHandlerName] ||
+ listener[genericHandlerName] ||
+ listener
+ );
listener.call(thisp, value, key, this);
- }
- }, this);
+ }, this);
+ } finally {
+ descriptor.isActive = false;
+ }
};
PropertyChanges.prototype.dispatchBeforeOwnPropertyChange = function (key, listener) {
@@ -5,6 +5,7 @@
https://github.com/motorola-mobility/montage/blob/master/LICENSE.md
*/
+require("../../shim");
var PropertyChanges = require("../../listen/property-changes");
describe("PropertyChanges", function () {

0 comments on commit 38d6540

Please sign in to comment.