Skip to content

Commit

Permalink
Optimize Observable
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jun 9, 2016
1 parent cd03d4e commit fde8e14
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ export class Observable {
* @param {function(TYPE)} handler Observer's instance.
*/
remove(handler) {
for (let i = 0; i < this.handlers_.length; i++) {
if (handler == this.handlers_[i]) {
this.handlers_.splice(i, 1);
break;
}
const index = this.handlers_.indexOf(handler);
if (index > -1) {
this.handlers_.splice(index, 1);
}
}

Expand All @@ -64,9 +62,11 @@ export class Observable {
* @param {TYPE} event
*/
fire(event) {
this.handlers_.forEach(handler => {
const handlers = this.handlers_;
for (let i = 0; i < handlers.length; i++) {
const handler = handlers[i];
handler(event);
});
}
}

/**
Expand Down

0 comments on commit fde8e14

Please sign in to comment.