Skip to content

Commit

Permalink
Remove try finally to restore performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotNB committed Jun 28, 2018
1 parent f6e8093 commit 7a8032b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions observable-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
};

Expand Down
2 changes: 1 addition & 1 deletion observable-slim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a8032b

Please sign in to comment.