-
Notifications
You must be signed in to change notification settings - Fork 754
/
FormToggleEvent.ts
50 lines (45 loc) · 1.39 KB
/
FormToggleEvent.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
40
41
42
43
44
45
46
47
48
49
50
import { OutgoingSocketEvents } from "../socket-messages";
import * as ClickEvent from "./ClickEvent";
import { Inputs } from "../index";
import { pluck } from "rxjs/operators/pluck";
import { filter } from "rxjs/operators/filter";
import { map } from "rxjs/operators/map";
import { Observable } from "rxjs/Observable";
import { withLatestFrom } from "rxjs/operators/withLatestFrom";
import { setElementToggleValue } from "../effects/set-element-toggle-value.effect";
export interface Payload {
tagName: string;
index: number;
value: any;
type: any;
checked: any;
}
export type OutgoingPayload = Payload;
export interface IncomingPayload extends OutgoingPayload {
pathname: string;
}
export function outgoing(
element: ClickEvent.ElementData,
props: { value: string; type: string; checked: boolean }
): [OutgoingSocketEvents.InputToggle, OutgoingPayload] {
return [
OutgoingSocketEvents.InputToggle,
{
...element,
...props
}
];
}
export function incomingInputsToggles(
xs: Observable<IncomingPayload>,
inputs: Inputs
) {
return xs.pipe(
withLatestFrom(
inputs.option$.pipe(pluck("ghostMode", "forms", "toggles")),
inputs.window$.pipe(pluck("location", "pathname"))
),
filter(([, toggles]) => toggles === true),
map(([event]) => setElementToggleValue(event))
);
}