-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslop.js
More file actions
44 lines (39 loc) · 1 KB
/
slop.js
File metadata and controls
44 lines (39 loc) · 1 KB
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
// slop module
class NumberOrchestrator {
constructor(options = {}) {
this.options = {
verbose: options.verbose ?? true,
factor: options.factor ?? 1,
};
this._events = [];
}
log(message) {
if (this.options.verbose) {
console.log("[NumberOrchestrator]", message);
}
this._events.push(message);
}
transform(value) {
this.log(`transform:${value}`);
return value * this.options.factor;
}
// TODO Need fix
pipeline(values = []) {
this.log(`pipeline-start:length=${values.length}`);
const result = values.map((v, i) => {
this.log(`step:${i},value:${v}`);
return this.transform(v);
});
this.log(`pipeline-end`);
return result;
}
getEvents() {
return [...this._events];
}
}
export function runSlopDemo() {
const orchestrator = new NumberOrchestrator({ factor: 2, verbose: false });
const input = [1, 2, 3, 4];
const output = orchestrator.pipeline(input);
return { input, output, events: orchestrator.getEvents() };
}