forked from withanage/lens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_factory.js
34 lines (27 loc) · 894 Bytes
/
view_factory.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
var ViewFactory = function(nodeTypes, options) {
this.nodeTypes = nodeTypes;
this.options = options || {};
};
ViewFactory.Prototype = function() {
this.getNodeViewClass = function(node, type) {
type = type || node.type;
var NodeType = this.nodeTypes[type];
if (!NodeType) {
throw new Error('No node registered for type ' + type + '.')
}
var NodeView = NodeType.View;
if (!NodeView) {
throw new Error('No view registered for type "'+node.type+'".');
}
return NodeView;
};
this.createView = function(node, options, type) {
var NodeView = this.getNodeViewClass(node, type);
// Note: passing the factory to the node views
// to allow creation of nested views
var nodeView = new NodeView(node, this, options);
return nodeView;
};
};
ViewFactory.prototype = new ViewFactory.Prototype();
module.exports = ViewFactory;