1 | var define;
|
2 | if (typeof define === "undefined") {
|
3 | define = function (classInstance) {
|
4 | classInstance (require, exports, module);
|
5 | };
|
6 | }
|
7 |
|
8 | define (function (require, exports, module) {
|
9 |
|
10 | var MODULE_NAME = 'dataflo.ws';
|
11 | var INITIATOR_PATH = 'initiator';
|
12 |
|
13 | var common = require ('./common'),
|
14 | color = {};
|
15 |
|
16 | color.error = function (message) {return message}
|
17 | color.path = function (message) {return message}
|
18 | color.dataflows = function (message) {return message}
|
19 |
|
20 | function DF () {
|
21 |
|
22 | }
|
23 |
|
24 | module.exports = DF;
|
25 |
|
26 | DF.registry = {};
|
27 |
|
28 | DF.common = common;
|
29 | DF.color = color;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | DF.instanceTypes = [ 'initiator', 'task' ];
|
35 |
|
36 | function registryLookup (instanceType, instanceName) {
|
37 | var instanceClass = DF.registry[instanceType] &&
|
38 | DF.registry[instanceType][instanceName];
|
39 |
|
40 | var error;
|
41 | if (!instanceClass) {
|
42 | error = new Error ("instance class not found for " + [instanceType, instanceName].join ("/"));
|
43 | throw error;
|
44 | }
|
45 |
|
46 | return instanceClass;
|
47 | }
|
48 |
|
49 | DF.instanceTypes.forEach (function (instanceType) {
|
50 | DF.registry[instanceType] = {};
|
51 | DF[instanceType] = function (instanceName) {
|
52 | return registryLookup (instanceType, instanceName);
|
53 | };
|
54 | });
|
55 |
|
56 | |
57 |
|
58 |
|
59 | DF.register = function (instanceType, instanceName, instanceClass) {
|
60 | if (!DF.registry[instanceType]) {
|
61 | console.warn(
|
62 | 'Unexpected instance type. Predefined types is: ['+instanceTypes.join(', ')+']'
|
63 | );
|
64 | return;
|
65 | }
|
66 |
|
67 | DF.registry[instanceType][instanceName] = instanceClass;
|
68 | };
|
69 |
|
70 | });
|