forked from zettajs/zetta-scientist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scientist.js
39 lines (30 loc) · 984 Bytes
/
scientist.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
var DeviceConfig = require('./device_config');
var config = exports.config = function(machine) {
var propsToCheck = ['_registry', '_log', '_pubsub'];
propsToCheck.forEach(function(k) {
if (machine[k] === 'undefined') {
throw new Error('Trying to initialize device without needed property set.');
}
});
var config = new DeviceConfig();
machine.init(config);
return config;
};
exports.init = function(machine) {
var cfg = config(machine);
machine._generate(cfg);
return machine;
}
exports.create = function(/* constructor, ...constructorArgs */) {
var args = Array.prototype.slice.call(arguments);
var constructor = args[0];
var constructorArgs = args.length > 1 ? args.slice(1) : undefined;
var machine;
if (constructor.prototype) {
machine = Object.create(constructor.prototype);
machine.constructor.apply(machine, constructorArgs);
} else if (constructor.init) {
machine = constructor;
}
return machine;
};