/
Util.purs
168 lines (137 loc) · 3.75 KB
/
Util.purs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
module Halogen.VDom.Util
( newMutMap
, pokeMutMap
, deleteMutMap
, unsafeFreeze
, unsafeLookup
, unsafeGetAny
, unsafeHasAny
, unsafeSetAny
, unsafeDeleteAny
, forE
, forEachE
, forInE
, replicateE
, diffWithIxE
, diffWithKeyAndIxE
, strMapWithIxE
, refEq
, createTextNode
, setTextContent
, createElement
, insertChildIx
, removeChild
, parentNode
, setAttribute
, removeAttribute
, addEventListener
, removeEventListener
, JsUndefined
, jsUndefined
) where
import Prelude
import Data.Function.Uncurried as Fn
import Data.Nullable (Nullable)
import Effect (Effect)
import Effect.Uncurried as EFn
import Foreign.Object (Object)
import Foreign.Object as Object
import Foreign.Object.ST (STObject)
import Foreign.Object.ST as STObject
import Halogen.VDom.Types (Namespace, ElemName)
import Unsafe.Coerce (unsafeCoerce)
import Web.DOM.Document (Document) as DOM
import Web.DOM.Element (Element) as DOM
import Web.DOM.Node (Node) as DOM
import Web.Event.EventTarget (EventListener) as DOM
newMutMap ∷ ∀ r a. Effect (STObject r a)
newMutMap = unsafeCoerce STObject.new
pokeMutMap ∷ ∀ r a. EFn.EffectFn3 String a (STObject r a) Unit
pokeMutMap = unsafeSetAny
deleteMutMap ∷ ∀ r a. EFn.EffectFn2 String (STObject r a) Unit
deleteMutMap = unsafeDeleteAny
unsafeFreeze ∷ ∀ r a. STObject r a → Object a
unsafeFreeze = unsafeCoerce
unsafeLookup ∷ ∀ a. Fn.Fn2 String (Object a) a
unsafeLookup = unsafeGetAny
foreign import unsafeGetAny
∷ ∀ a b. Fn.Fn2 String a b
foreign import unsafeHasAny
∷ ∀ a. Fn.Fn2 String a Boolean
foreign import unsafeSetAny ∷ ∀ a b. EFn.EffectFn3 String a b Unit
foreign import unsafeDeleteAny
∷ ∀ a. EFn.EffectFn2 String a Unit
foreign import forE
∷ ∀ a b
. EFn.EffectFn2
(Array a)
(EFn.EffectFn2 Int a b)
(Array b)
foreign import forEachE
∷ ∀ a
. EFn.EffectFn2
(Array a)
(EFn.EffectFn1 a Unit)
Unit
foreign import forInE
∷ ∀ a
. EFn.EffectFn2
(Object.Object a)
(EFn.EffectFn2 String a Unit)
Unit
foreign import replicateE
∷ ∀ a
. EFn.EffectFn2
Int
(Effect a)
Unit
foreign import diffWithIxE
∷ ∀ b c d
. EFn.EffectFn5
(Array b)
(Array c)
(EFn.EffectFn3 Int b c d)
(EFn.EffectFn2 Int b Unit)
(EFn.EffectFn2 Int c d)
(Array d)
foreign import diffWithKeyAndIxE
∷ ∀ a b c d
. EFn.EffectFn6
(Object.Object a)
(Array b)
(b → String)
(EFn.EffectFn4 String Int a b c)
(EFn.EffectFn2 String a d)
(EFn.EffectFn3 String Int b c)
(Object.Object c)
foreign import strMapWithIxE
∷ ∀ a b
. EFn.EffectFn3
(Array a)
(a → String)
(EFn.EffectFn3 String Int a b)
(Object.Object b)
foreign import refEq
∷ ∀ a b. Fn.Fn2 a b Boolean
foreign import createTextNode
∷ EFn.EffectFn2 String DOM.Document DOM.Node
foreign import setTextContent
∷ EFn.EffectFn2 String DOM.Node Unit
foreign import createElement
∷ EFn.EffectFn3 (Nullable Namespace) ElemName DOM.Document DOM.Element
foreign import insertChildIx
∷ EFn.EffectFn3 Int DOM.Node DOM.Node Unit
foreign import removeChild
∷ EFn.EffectFn2 DOM.Node DOM.Node Unit
foreign import parentNode
∷ EFn.EffectFn1 DOM.Node DOM.Node
foreign import setAttribute
∷ EFn.EffectFn4 (Nullable Namespace) String String DOM.Element Unit
foreign import removeAttribute
∷ EFn.EffectFn3 (Nullable Namespace) String DOM.Element Unit
foreign import addEventListener
∷ EFn.EffectFn3 String DOM.EventListener DOM.Element Unit
foreign import removeEventListener
∷ EFn.EffectFn3 String DOM.EventListener DOM.Element Unit
foreign import data JsUndefined ∷ Type
foreign import jsUndefined ∷ JsUndefined