Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Remove isObservable check in addObserver. This isn't really adding mu…
Browse files Browse the repository at this point in the history
…ch as the open() call will throw if it's absent.

Since the check is critical path, I just assume remove it.

[email protected], arv
BUG=

Review URL: https://codereview.appspot.com/35850047
  • Loading branch information
rafaelw committed Dec 18, 2013
1 parent 3fdf254 commit eab1b5c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
15 changes: 1 addition & 14 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@
return copy;
}

function isObservable(obj) {
return obj &&
typeof obj.open == 'function' &&
typeof obj.close == 'function';
}

var UNOPENED = 0;
var OPENED = 1;
var CLOSED = 2;
Expand Down Expand Up @@ -797,14 +791,8 @@
if (this.state_ != UNOPENED)
throw Error('Cannot add observers once started.');

if (!isObservable(observer))
throw Error('Object must be observable');

var value = observer.open(this.observerChanged_, this);
this.hasObservers_ = true;

observer.open(this.observerChanged_, this);
var value = observer.value;

this.observed_.push(observerSentinel, observer);
this.value_.push(value);
},
Expand Down Expand Up @@ -1472,7 +1460,6 @@

global.Observer = Observer;
global.Observer.hasObjectObserve = hasObserve;
global.Observer.isObservable = isObservable;
global.ArrayObserver = ArrayObserver;
global.ArrayObserver.calculateSplices = function(current, previous) {
return arraySplice.calculateSplices(current, previous);
Expand Down
8 changes: 0 additions & 8 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,14 +1046,6 @@ suite('CompoundObserver Tests', function() {
function setValueFn(value) { return value / 2; }

var compound = new CompoundObserver;
assert.throws(function () {
compound.addObserver({ open: function() {} });
});

assert.throws(function () {
compound.addObserver({ close: function() {} });
});

assert.throws(function () {
compound.addObserver(1);
});
Expand Down

0 comments on commit eab1b5c

Please sign in to comment.