Skip to content

Commit e2ab059

Browse files
authored
Account for duplicate handler definitions (#7)
1 parent b0822fe commit e2ab059

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Halogen/VDom/DOM/Prop.purs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ buildProp emit el = render
106106
Fn.runFn3 setProperty prop val el
107107
pure v
108108
Handler (DOM.EventType ty) f → do
109-
ref ← Ref.newRef f
110-
let
111-
listener = DOM.eventListener \ev → do
112-
f' ← Ref.readRef ref
113-
mbEmit (f' ev)
114-
Fn.runFn3 Util.pokeMutMap ty (Tuple listener ref) events
115-
Fn.runFn3 Util.addEventListener ty listener el
116-
pure v
109+
case Fn.runFn2 Util.unsafeGetAny ty events of
110+
handler | Fn.runFn2 Util.unsafeHasAny ty events → do
111+
Ref.writeRef (snd handler) f
112+
pure v
113+
_ → do
114+
ref ← Ref.newRef f
115+
let
116+
listener = DOM.eventListener \ev → do
117+
f' ← Ref.readRef ref
118+
mbEmit (f' ev)
119+
Fn.runFn3 Util.pokeMutMap ty (Tuple listener ref) events
120+
Fn.runFn3 Util.addEventListener ty listener el
121+
pure v
117122
Ref f → do
118123
mbEmit (f (Created el))
119124
pure v
@@ -138,7 +143,7 @@ buildProp emit el = render
138143
Fn.runFn3 setProperty prop2 val2 el
139144
pure v2
140145
_ →
141-
pure v2
146+
Util.effPure v2
142147
_, _ → do
143148
Fn.runFn3 setProperty prop2 val2 el
144149
pure v2

0 commit comments

Comments
 (0)