Skip to content

Switcher

Dan Stocker edited this page Jun 1, 2019 · 1 revision

Usage: createSwitcher<T>(fields: Array<keyof T>)

Module: flowcode-flow

Type: Switcher<P extends string, V>

Input ports:

  • all: {d_val: V, st_pos: P}
  • d_val: V
  • st_pos: P

Output ports:

  • K in P: V (user-defined)
  • b_all: {d_val: V, st_pos: P}
  • b_d_val: V

Forwards input to one of the user-defined output ports, depending of the current position of the switcher. Bounces input when the position doesn't match any of the outputs.

import {connect} from "flowcode";
import {createSwitcher} from "flowcode-flow";
const switcher = createSwitcher(["foo", "bar"]);
connect(switcher.o.foo, console.log);
switcher.i.all({d_val: "a", st_pos: "foo"}); // logs: "a"
Clone this wiki locally