2016-02-28 20:21:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-29 20:53:42 +00:00
|
|
|
var BaseNode = require('./base').Node;
|
|
|
|
|
|
|
|
exports.BaseNode = BaseNode;
|
|
|
|
|
2016-02-28 20:21:08 +00:00
|
|
|
var constructors = {
|
|
|
|
local: require('./local').Node
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.register = function(type, constructor) {
|
2016-02-29 20:53:42 +00:00
|
|
|
constructors[type] = constructor;
|
2016-02-28 20:21:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.createNode = function(params) {
|
|
|
|
if (params.type in constructors === false) {
|
2016-02-29 20:53:42 +00:00
|
|
|
throw new Error('Unknown node type: ' + params.type);
|
2016-02-28 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var Constructor = constructors[params.type];
|
|
|
|
return new Constructor(params);
|
|
|
|
};
|