This repository has been archived by the owner on Jun 8, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Methods are now proxies to Backbone's `listenTo` and `stopListening`. Add a deprecation warning when using `bindTo` and `unbindFromAll`. Cleanup tests, removing unneeded assertions and updating `Observer`s tests to ensure they call through to `listenTo` and `stopListening`. Closes #21.
- Loading branch information
1 parent
1e6b24e
commit 383e318
Showing
3 changed files
with
31 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
Support.Observer = function() {}; | ||
(function() { | ||
|
||
_.extend(Support.Observer.prototype, { | ||
bindTo: function(source, event, callback) { | ||
source.bind(event, callback, this); | ||
this.bindings = this.bindings || []; | ||
this.bindings.push({ source: source, event: event, callback: callback }); | ||
}, | ||
Support.Observer = function() {}; | ||
|
||
unbindFromAll: function() { | ||
_.each(this.bindings, function(binding) { | ||
binding.source.unbind(binding.event, binding.callback); | ||
}); | ||
this.bindings = [] | ||
// `console` is not defined when the Developer Tools are not open in older | ||
// versions of Internet Explorer | ||
function deprecate(message) { | ||
/* global console */ | ||
if ( console && console.warn ) { | ||
console.warn(message); | ||
} | ||
} | ||
}); | ||
|
||
_.extend(Support.Observer.prototype, { | ||
bindTo: function(source, event, callback) { | ||
deprecate("Using #bindTo has been deprecated. Use #listenTo instead."); | ||
this.listenTo(source, event, callback); | ||
}, | ||
|
||
unbindFromAll: function() { | ||
deprecate( | ||
"Using #unbindFromAll has been deprecated. Use #stopListening instead." | ||
); | ||
|
||
this.stopListening(); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters