-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
75 lines (65 loc) · 4.14 KB
/
index.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/** @license MIT License (c) copyright 2015-2016 original author or authors */
/** @author Brian Cavalier */
import { currentTime } from '@most/scheduler'
// domEvent :: (EventTarget t, Event e) => String -> t -> boolean=false -> Stream e
export const domEvent = (event, node, capture = false) =>
new DomEvent(event, node, capture)
export const blur = (node, capture = false) => domEvent('blur', node, capture)
export const focus = (node, capture = false) => domEvent('focus', node, capture)
export const focusin = (node, capture = false) => domEvent('focusin', node, capture)
export const focusout = (node, capture = false) => domEvent('focusout', node, capture)
export const click = (node, capture = false) => domEvent('click', node, capture)
export const dblclick = (node, capture = false) => domEvent('dblclick', node, capture)
export const mousedown = (node, capture = false) => domEvent('mousedown', node, capture)
export const mouseup = (node, capture = false) => domEvent('mouseup', node, capture)
export const mousemove = (node, capture = false) => domEvent('mousemove', node, capture)
export const mouseover = (node, capture = false) => domEvent('mouseover', node, capture)
export const mouseenter = (node, capture = false) => domEvent('mouseenter', node, capture)
export const mouseout = (node, capture = false) => domEvent('mouseout', node, capture)
export const mouseleave = (node, capture = false) => domEvent('mouseleave', node, capture)
export const change = (node, capture = false) => domEvent('change', node, capture)
export const select = (node, capture = false) => domEvent('select', node, capture)
export const submit = (node, capture = false) => domEvent('submit', node, capture)
export const keydown = (node, capture = false) => domEvent('keydown', node, capture)
export const keypress = (node, capture = false) => domEvent('keypress', node, capture)
export const keyup = (node, capture = false) => domEvent('keyup', node, capture)
export const input = (node, capture = false) => domEvent('input', node, capture)
export const contextmenu = (node, capture = false) => domEvent('contextmenu', node, capture)
export const resize = (node, capture = false) => domEvent('resize', node, capture)
export const scroll = (node, capture = false) => domEvent('scroll', node, capture)
export const error = (node, capture = false) => domEvent('error', node, capture)
export const hashchange = (node, capture = false) => domEvent('hashchange', node, capture)
export const popstate = (node, capture = false) => domEvent('popstate', node, capture)
export const load = (node, capture = false) => domEvent('load', node, capture)
export const unload = (node, capture = false) => domEvent('unload', node, capture)
export const pointerdown = (node, capture = false) => domEvent('pointerdown', node, capture)
export const pointerup = (node, capture = false) => domEvent('pointerup', node, capture)
export const pointermove = (node, capture = false) => domEvent('pointermove', node, capture)
export const pointerover = (node, capture = false) => domEvent('pointerover', node, capture)
export const pointerenter = (node, capture = false) => domEvent('pointerenter', node, capture)
export const pointerout = (node, capture = false) => domEvent('pointerout', node, capture)
export const pointerleave = (node, capture = false) => domEvent('pointerleave', node, capture)
export const touchstart = (node, capture = false) => domEvent('touchstart', node, capture)
export const touchend = (node, capture = false) => domEvent('touchend', node, capture)
export const touchmove = (node, capture = false) => domEvent('touchmove', node, capture)
export const touchcancel = (node, capture = false) => domEvent('touchcancel', node, capture)
class DomEvent {
constructor (event, node, capture) {
this.event = event
this.node = node
this.capture = capture
}
run (sink, scheduler) {
const send = e => tryEvent(currentTime(scheduler), e, sink)
const dispose = () => this.node.removeEventListener(this.event, send, this.capture)
this.node.addEventListener(this.event, send, this.capture)
return { dispose }
}
}
function tryEvent (t, x, sink) {
try {
sink.event(t, x)
} catch (e) {
sink.error(t, e)
}
}