Skip to content

Commit

Permalink
Clean up arrayChange notifySubscribers wrapper
Browse files Browse the repository at this point in the history
Added logic to remember and restore the
underlyingNotifySubscribersFunction captured by the trackChanges method
when using a trackArrayChanges extender.
  • Loading branch information
ThomasMichon committed Jan 13, 2016
1 parent e9e653e commit fd71d33
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/subscribables/observableArray.changeTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ko.extenders['trackArrayChanges'] = function(target, options) {
cachedDiff = null,
arrayChangeSubscription,
pendingNotifications = 0,
underlyingNotifySubscribersFunction,
underlyingBeforeSubscriptionAddFunction = target.beforeSubscriptionAdd,
underlyingAfterSubscriptionRemoveFunction = target.afterSubscriptionRemove;

Expand All @@ -31,6 +32,10 @@ ko.extenders['trackArrayChanges'] = function(target, options) {
if (underlyingAfterSubscriptionRemoveFunction)
underlyingAfterSubscriptionRemoveFunction.call(target, event);
if (event === arrayChangeEventName && !target.hasSubscriptionsForEvent(arrayChangeEventName)) {
if (underlyingNotifySubscribersFunction) {
target['notifySubscribers'] = underlyingNotifySubscribersFunction;
underlyingNotifySubscribersFunction = undefined;
}
arrayChangeSubscription.dispose();
trackingChanges = false;
}
Expand All @@ -45,7 +50,7 @@ ko.extenders['trackArrayChanges'] = function(target, options) {
trackingChanges = true;

// Intercept "notifySubscribers" to track how many times it was called.
var underlyingNotifySubscribersFunction = target['notifySubscribers'];
underlyingNotifySubscribersFunction = target['notifySubscribers'];
target['notifySubscribers'] = function(valueToNotify, event) {
if (!event || event === defaultEvent) {
++pendingNotifications;
Expand Down

0 comments on commit fd71d33

Please sign in to comment.