From 7a8032bb88b322e0cf86948c0865858e7234d4f1 Mon Sep 17 00:00:00 2001 From: ElliotNB Date: Thu, 28 Jun 2018 00:16:33 -0700 Subject: [PATCH] Remove try finally to restore performance. --- observable-slim.js | 26 ++++++++++++++++---------- observable-slim.min.js | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/observable-slim.js b/observable-slim.js index 142304f..4775836 100644 --- a/observable-slim.js +++ b/observable-slim.js @@ -90,21 +90,27 @@ var ObservableSlim = (function() { if (domDelay === true) { setTimeout(function() { if (numChanges === changes.length) { + + // we create a copy of changes before passing it to the observer functions because even if the observer function + // throws an error, we still need to ensure that changes is reset to an empty array so that old changes don't persist + var changesCopy = changes.slice(0); + changes = []; + // invoke any functions that are observing changes - try { - for (var i = 0; i < observable.observers.length; i++) observable.observers[i](changes); - } finally { - changes = []; - } + for (var i = 0; i < observable.observers.length; i++) observable.observers[i](changesCopy); + } },10); } else { + + // we create a copy of changes before passing it to the observer functions because even if the observer function + // throws an error, we still need to ensure that changes is reset to an empty array so that old changes don't persist + var changesCopy = changes.slice(0); + changes = []; + // invoke any functions that are observing changes - try { - for (var i = 0; i < observable.observers.length; i++) observable.observers[i](changes); - } finally { - changes = []; - } + for (var i = 0; i < observable.observers.length; i++) observable.observers[i](changesCopy); + } }; diff --git a/observable-slim.min.js b/observable-slim.min.js index 3c80c54..71ba881 100644 --- a/observable-slim.min.js +++ b/observable-slim.min.js @@ -1 +1 @@ -var ObservableSlim=function(){var u=[],d=[],x=[],P=null,f=function(e,l,r,n){var v=r||null,i=n||"",g=[],h=function(e,r,n){var t=null;return t=e instanceof Array?""!==i?i:r:""!==i?i+"."+r:r,!0===n&&(t="/"+t.replace(/\./g,"/")),t},b=function(r){if(!0!==v.paused)if(!0===l)setTimeout(function(){if(r===g.length)try{for(var e=0;e