Skip to content

Commit 7c5b25b

Browse files
committed
Allowing Epoxy components to reference custom super-classes.
1 parent d89b6c0 commit 7c5b25b

5 files changed

+49
-55
lines changed

backbone.epoxy.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121

2222
}(this, function(_, Backbone) {
23-
23+
2424
// Epoxy namespace:
2525
var Epoxy = Backbone.Epoxy = {};
2626

@@ -49,28 +49,25 @@
4949
return extend;
5050
}
5151
};
52-
53-
// Partial application for calling method implementations of a super-class object:
54-
function superClass(sup) {
55-
return function(instance, method, args) {
56-
return sup.prototype[ method ].apply(instance, args);
57-
};
52+
53+
// Calls method implementations of a super-class object:
54+
function _super(instance, method, args) {
55+
return instance._super.prototype[method].apply(instance, args);
5856
}
59-
60-
57+
6158
// Epoxy.Model
6259
// -----------
6360
var modelMap;
64-
var modelSuper = superClass(Backbone.Model);
6561
var modelProps = ['computeds'];
6662

6763
Epoxy.Model = Backbone.Model.extend({
68-
64+
_super: Backbone.Model,
65+
6966
// Backbone.Model constructor override:
7067
// configures computed model attributes around the underlying native Backbone model.
7168
constructor: function(attributes, options) {
7269
_.extend(this, _.pick(options||{}, modelProps));
73-
modelSuper(this, 'constructor', arguments);
70+
_super(this, 'constructor', arguments);
7471
this.initComputeds(attributes, options);
7572
},
7673

@@ -95,7 +92,7 @@
9592
}
9693

9794
// Default to native Backbone.Model get operation:
98-
return modelSuper(this, 'get', arguments);
95+
return _super(this, 'get', arguments);
9996
},
10097

10198
// Backbone.Model.set() override:
@@ -124,13 +121,13 @@
124121
}
125122

126123
// Pass all resulting set params along to the underlying Backbone Model.
127-
return modelSuper(this, 'set', [params, options]);
124+
return _super(this, 'set', [params, options]);
128125
},
129126

130127
// Backbone.Model.toJSON() override:
131128
// adds a 'computed' option, specifying to include computed attributes.
132129
toJSON: function(options) {
133-
var json = modelSuper(this, 'toJSON', arguments);
130+
var json = _super(this, 'toJSON', arguments);
134131

135132
if (options && options.computed) {
136133
_.each(this.c(), function(computed, attribute) {
@@ -145,7 +142,7 @@
145142
// clears all computed attributes before destroying.
146143
destroy: function() {
147144
this.clearComputeds();
148-
return modelSuper(this, 'destroy', arguments);
145+
return _super(this, 'destroy', arguments);
149146
},
150147

151148
// Computed namespace manager:
@@ -950,17 +947,16 @@
950947
// Epoxy.View
951948
// ----------
952949
var viewMap;
953-
var viewSuper = superClass(Backbone.View);
954950
var viewProps = ['viewModel', 'bindings', 'bindingFilters', 'bindingHandlers', 'bindingSources', 'computeds'];
955951

956-
957952
Epoxy.View = Backbone.View.extend({
958-
953+
_super: Backbone.View,
954+
959955
// Backbone.View constructor override:
960956
// sets up binding controls around call to super.
961957
constructor: function(options) {
962958
_.extend(this, _.pick(options||{}, viewProps));
963-
viewSuper(this, 'constructor', arguments);
959+
_super(this, 'constructor', arguments);
964960
this.applyBindings();
965961
},
966962

@@ -1091,7 +1087,7 @@
10911087
// unbinds the view before performing native removal tasks.
10921088
remove: function() {
10931089
this.removeBindings();
1094-
viewSuper(this, 'remove', arguments);
1090+
_super(this, 'remove', arguments);
10951091
}
10961092

10971093
}, mixins);

0 commit comments

Comments
 (0)