-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.ts
39 lines (36 loc) · 1.57 KB
/
input.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
import {Cell, CellLoop, CellSink, Operational, Stream, StreamSink, Unit} from "sodiumjs";
import {IInputsInterface, Keys, UpDown} from "../types";
const pricePropsFactory = ({price}) => {
return new CellSink<number>(price);
};
export default function getInputs(priceConfigs,
sClick1: StreamSink<UpDown>,
sClick2: StreamSink<UpDown>,
sClick3: StreamSink<UpDown>): IInputsInterface {
const [cNozzle1, cNozzle2, cNozzle3] = [sClick1, sClick2, sClick3].map(sClick => {
const cNozzle = new CellLoop<UpDown>();
cNozzle.loop(sClick
.snapshot(cNozzle, (click, direction) => direction === UpDown.DOWN
? UpDown.UP
: UpDown.DOWN)
.hold(UpDown.DOWN));
return cNozzle;
});
const [sNozzle1, sNozzle2, sNozzle3] = [cNozzle1, cNozzle2, cNozzle3]
.map(innerCNozzle => Operational.updates(innerCNozzle));
const [cPrice1, cPrice2, cPrice3] = priceConfigs.map(conf => pricePropsFactory(conf));
const csClearSale: CellSink<StreamSink<Unit>> = new CellSink(new StreamSink<Unit>());
const sClearSale: Stream <Unit> = Cell.switchS(csClearSale);
const sKeypad = new StreamSink<Keys>();
const sFuelPulses = new StreamSink<number>();
const cCalibration = new Cell<number>(0.001);
return {
cNozzle1, cNozzle2, cNozzle3,
sNozzle1, sNozzle2, sNozzle3,
sKeypad,
sFuelPulses,
cCalibration,
cPrice1, cPrice2, cPrice3,
sClearSale, csClearSale,
};
}