@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
24 lines • 765 B
JavaScript
import filter from '../pin/filter';
import { Agent } from './agent';
export class Switch extends Agent {
constructor(...cases) {
super({
inputs: ['target'],
outputs: cases.map((_, index) => index.toString()),
});
this.cases = cases;
}
get target() { return this.in('target'); }
case(index) { return this.out(index); }
createOutput(label) {
this.checkOutput(label);
let _case = this.cases[label];
return this.target
.to((typeof _case === 'function') ?
filter(_case) :
filter((value) => _case === value));
}
}
export function _switch(...cases) { return new Switch(...cases); }
export default _switch;
//# sourceMappingURL=switch.js.map