MCPcopy
hub / github.com/jorgebucaran/hyperapp / on

Function on

packages/events/index.js:10–36  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

8}
9
10const on = (type) =>
11 fx((dispatch, action) => {
12 if (!listeners[type]) {
13 listeners[type] = new Map()
14 addEventListener(type, globalListener)
15 }
16
17 listeners[type].set(
18 dispatch,
19 (listeners[type].get(dispatch) || []).concat(action)
20 )
21
22 return () => {
23 const actions = listeners[type].get(dispatch).filter((a) => a !== action)
24
25 listeners[type].set(dispatch, actions)
26
27 if (
28 actions.length === 0 &&
29 listeners[type].delete(dispatch) &&
30 listeners[type].size === 0
31 ) {
32 delete listeners[type]
33 removeEventListener(type, globalListener)
34 }
35 }
36 })
37
38export const onMouseMove = on("mousemove")
39export const onMouseDown = on("mousedown")

Callers 1

index.jsFile · 0.85

Calls 1

fxFunction · 0.85

Tested by

no test coverage detected