-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppRouter.js
48 lines (43 loc) · 1.05 KB
/
AppRouter.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
class AppRouter extends Backbone.Router {
initialize({ $rootEl }) {
this.$rootEl = $rootEl;
this.friendFilter = new FriendFilter();
this.friends = new Friends();
this.timers = new Timers();
}
baseView() {
if (!this._baseView) {
this._baseView = new BaseView({ model: this.friendFilter });
this.$rootEl.html(this._baseView.$el);
this._baseView.render();
}
return this._baseView;
}
friendIndex() {
let view = new FriendIndexView({
collection: this.friends,
model: this.friendFilter,
timers: this.timers
});
this._swapView(view);
}
hamble() {
let view = new HambleView();
this._swapView(view);
}
_swapView(view) {
if (this._currentView) {
if (this.friendFilter.get('removeChildren')) {
this._currentView.removePlus();
} else {
this._currentView.remove();
}
}
this._currentView = view;
this.baseView().$('#view').html(view.render().$el);
}
}
AppRouter.prototype.routes = {
'': 'friendIndex',
'hamble': 'hamble'
}