-
Notifications
You must be signed in to change notification settings - Fork 0
/
multistage.ts
33 lines (28 loc) · 931 Bytes
/
multistage.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
import { Stage } from './stage';
export class Multistage {
protected _stages : (Stage|Multistage)[] = [];
stages() : (Stage|Multistage)[];
stages(stage: Stage|Multistage, ...stages : (Stage|Multistage)[]) : this;
stages(stage?: Stage|Multistage, ...stages : (Stage|Multistage)[]) : this | (Stage|Multistage)[] {
if(stage) {
this._stages.push(stage, ...stages);
return this;
}
return this._stages;
}
getStage(name: string) {
return [ ...this ].find(s => s.getName() === name);
}
*[Symbol.iterator](): Iterator<Stage> {
for(const stage of this.stages()) {
if(stage instanceof Multistage) {
yield* stage;
} else {
yield stage;
}
}
}
}
export function multistage(...args : ConstructorParameters<typeof Multistage>) {
return new Multistage(...args);
}