-
Notifications
You must be signed in to change notification settings - Fork 3
/
vm.js
31 lines (27 loc) · 776 Bytes
/
vm.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
var $ = require('browserify-jquery')
, _ = require('underscore')
, Backbone = require('backbone')
, Events = require('events')
var views = {};
var create = function (context, name, View, options) {
// View clean up isn't actually implemented yet but will simply call .clean, .remove and .unbind
if(typeof views[name] !== 'undefined') {
views[name].undelegateEvents();
if(typeof views[name].clean === 'function') {
views[name].clean();
}
}
var view = new View(options);
views[name] = view;
if(typeof context.children === 'undefined'){
context.children = {};
context.children[name] = view;
} else {
context.children[name] = view;
}
Events.trigger('viewCreated');
return view;
};
module.exports = {
create: create
};