-
Notifications
You must be signed in to change notification settings - Fork 754
/
ClickEvent.ts
41 lines (37 loc) · 1.16 KB
/
ClickEvent.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
import { OutgoingSocketEvents } from "../socket-messages";
import { Inputs } from "../index";
import { Observable } from "rxjs/Observable";
import { pluck } from "rxjs/operators/pluck";
import { filter } from "rxjs/operators/filter";
import { map } from "rxjs/operators/map";
import { withLatestFrom } from "rxjs/operators/withLatestFrom";
import { simulateClick } from "../effects/simulate-click.effect";
export interface ElementData {
tagName: string;
index: number;
}
export interface IncomingPayload extends ElementData {
pathname: string;
}
export function outgoing(
data: ElementData
): [OutgoingSocketEvents.Click, ElementData] {
return [OutgoingSocketEvents.Click, data];
}
export function incomingHandler$(
xs: Observable<IncomingPayload>,
inputs: Inputs
) {
return xs.pipe(
withLatestFrom(
inputs.option$.pipe(pluck("ghostMode", "clicks")),
inputs.window$.pipe(pluck("location", "pathname"))
),
filter(([event, canClick, pathname]) => {
return canClick && event.pathname === pathname;
}),
map(([event]) => {
return simulateClick(event);
})
);
}