Skip to content

Commit 363b852

Browse files
authored
Propagate SyntheticEvent to 'this' in preventDefault and stopPropagation functions (#48)
1 parent a598a32 commit 363b852

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/React/Basic/DOM/Events.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
export const propagateThis = (f) => (t) => () => {
4+
return f.call(t);
5+
}

src/React/Basic/DOM/Events.purs

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ nativeEvent = unsafeEventFn \e -> (unsafeCoerce e).nativeEvent
102102

103103
preventDefault :: EventFn SyntheticEvent SyntheticEvent
104104
preventDefault = unsafeEventFn \e -> unsafePerformEffect do
105-
_ <- (unsafeCoerce e).preventDefault
105+
_ <- propagateThis (unsafeCoerce e).preventDefault e
106106
pure e
107107

108108
isDefaultPrevented :: EventFn SyntheticEvent Boolean
@@ -111,7 +111,7 @@ isDefaultPrevented = unsafeEventFn \e -> unsafePerformEffect do
111111

112112
stopPropagation :: EventFn SyntheticEvent SyntheticEvent
113113
stopPropagation = unsafeEventFn \e -> unsafePerformEffect do
114-
_ <- (unsafeCoerce e).stopPropagation
114+
_ <- propagateThis (unsafeCoerce e).stopPropagation e
115115
pure e
116116

117117
isPropagationStopped :: EventFn SyntheticEvent Boolean
@@ -207,3 +207,5 @@ clipboardData = unsafeEventFn \e -> toMaybe (unsafeCoerce e).clipboardData
207207
-- \ Composition Events
208208
compositionData :: EventFn SyntheticEvent (Maybe String)
209209
compositionData = unsafeEventFn \e -> toMaybe (unsafeCoerce e).data
210+
211+
foreign import propagateThis :: forall f t a. f -> t -> Effect a

0 commit comments

Comments
 (0)