Skip to content

Commit be55b61

Browse files
committed
Merge pull request #220 from DouweM/backbone-plugin
Add plugin for Backbone.js.
2 parents 5e75116 + 686377f commit be55b61

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

plugins/backbone.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Backbone.js plugin
3+
*
4+
* Patches Backbone.Events callbacks.
5+
*/
6+
;(function(window, Raven, Backbone) {
7+
'use strict';
8+
9+
// quit if Backbone isn't on the page
10+
if (!Backbone) {
11+
return;
12+
}
13+
14+
// We're too late to catch all of these by simply patching Backbone.Events.on
15+
var affectedObjects = [
16+
Backbone.Events,
17+
Backbone,
18+
Backbone.Model.prototype,
19+
Backbone.Collection.prototype,
20+
Backbone.View.prototype,
21+
Backbone.Router.prototype,
22+
Backbone.History.prototype
23+
];
24+
25+
for (var i = 0; i < affectedObjects.length; i++) {
26+
var affected = affectedObjects[i];
27+
28+
var _oldOn = affected.on;
29+
affected.on = function BackboneEventsOn(name, callback, context) {
30+
var _callback;
31+
if (callback._callback) {
32+
_callback = callback._callback;
33+
} else {
34+
_callback = callback;
35+
}
36+
37+
callback = Raven.wrap(callback);
38+
callback._callback = _callback;
39+
40+
return _oldOn.call(this, name, callback, context);
41+
};
42+
43+
affected.bind = affected.on;
44+
}
45+
46+
}(this, Raven, window.Backbone));

0 commit comments

Comments
 (0)