-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
79 lines (68 loc) · 1.96 KB
/
index.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// <reference path="typings/tsd.d.ts" />
/// <reference path="Symbol.d.ts" />
'use strict';
let Rx = require('@reactivex/rxjs');
import GustavGraph from './GustavGraph';
interface NodeFactory {
(...config:any[]): symbol;
}
interface NodeCollection {
source: string[];
transformer: string[];
sink: string[];
}
class Gustav {
ggraph: GustavGraph;
registeredNodes: NodeCollection;
constructor() {
this.ggraph = new GustavGraph();
this.registeredNodes = {
source: [],
transformer: [],
sink: []
};
}
// TODO: new type of registration that's just a singleton
// Just calls NodeFactory and returns the symbol
private register(type: string, name: string, factory): NodeFactory {
// TODO: Return some sort of object so this can be chained
// let splitText = SplitText()
// .addDep(fetchPageText);
this.registeredNodes[type].push(name);
return (...config) => {
// Attempt to detect config to make symbol tag more descriptive
let symbolTag = name;
if (config.length) {
if(!(config[0] instanceof Object)) {
symbolTag += '-' + config[0];
} else if (config[0].id) {
symbolTag += '-' + config[0].id;
}
}
let sym = Symbol(symbolTag);
this.ggraph.nodes[sym] = {
type,
init: factory.apply(null, config)
};
return sym;
};
}
init () {
this.ggraph.makeGraph();
}
addDep (from: symbol, to: symbol) {
this.ggraph.addEdge(from, to);
}
source(name: string, factory) { return this.register('source', name, factory)}
transformer(name: string, factory) { return this.register('transformer', name, factory)}
sink(name: string, factory) { return this.register('sink', name, factory)}
};
// REVIEW: How to handle below:
// let gustavs = {};
// let getGustavs = (name:string) => {
// if (!gustavs[name]) {
// gustavs[name] = new Gustav();
// }
// return gustavs[name];
// };
export var gustav = new Gustav();