-
Notifications
You must be signed in to change notification settings - Fork 6
/
view.js
56 lines (42 loc) · 1.49 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
define([
'jquery',
'backbone',
'underscore',
'component/eventBinder',
'component/subViewHandler'
],
function($, Backbone, _, EventBinder, SubViewHandler) {
var View = Backbone.View.extend({
constructor: function() {
var eventBinder = new EventBinder();
_.extend(this, eventBinder);
var subViewHandler = new SubViewHandler();
_.extend(this, subViewHandler);
Backbone.View.prototype.constructor.apply(this, arguments);
},
destroy: function() {
// Unbind all events bound in the view, i.e. those bound
// with `this.bindTo`
this.unbindAll();
// Unbind all events that are bound to the view, i.e.
// those bound with `this.on`
this.off();
// Remove the view from the DOM
this.remove();
// Recusively destroy all subviews
this.destroySubViews();
},
renderTemplate: function() {
var data = {};
_.each(arguments, function(arg) {
_.extend(data, arg);
});
var html = this.parseTemplate(this.template, data);
this.$el.html(html);
},
parseTemplate: function(template, data) {
return template(data);
}
});
return View;
});