Skip to content

Update Backbone.js plugin to handle event map syntax. #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions plugins/backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ if (!Backbone) {

function makeBackboneEventsOn(oldOn) {
return function BackboneEventsOn(name, callback, context) {
var _callback = callback._callback || callback;
callback = Raven.wrap(callback);
callback._callback = _callback;
var wrapCallback = function (cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess at this point, we should probably just make this entire function safe and check if it's a function before wrapping. If it's not a function, just noop and return cb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (Object.prototype.toString.call(cb) === '[object Function]') {
var _callback = cb._callback || cb;
cb = Raven.wrap(cb);
cb._callback = _callback;
}
return cb;
};
if (Object.prototype.toString.call(name) === '[object Object]') {
// Handle event maps.
for (var key in name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to check if key is inside name's prototype.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (name.hasOwnProperty(key)) {
name[key] = wrapCallback(name[key]);
}
}
} else {
callback = wrapCallback(callback);
}
return oldOn.call(this, name, callback, context);
};
}
Expand Down