From fcb50912b4ad1925599d5aa112aa2c6258e18fb4 Mon Sep 17 00:00:00 2001 From: Kirill Kuznetsov Date: Tue, 10 Jan 2023 13:47:20 +0300 Subject: [PATCH] Propagate SyntheticEvent to 'this' in preventDefault and stopPropagation functions --- src/React/Basic/DOM/Events.js | 5 +++++ src/React/Basic/DOM/Events.purs | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/React/Basic/DOM/Events.js diff --git a/src/React/Basic/DOM/Events.js b/src/React/Basic/DOM/Events.js new file mode 100644 index 0000000..8e46b86 --- /dev/null +++ b/src/React/Basic/DOM/Events.js @@ -0,0 +1,5 @@ +"use strict"; + +export const propagateThis = (f) => (t) => () => { + return f.call(t); +} diff --git a/src/React/Basic/DOM/Events.purs b/src/React/Basic/DOM/Events.purs index 0207c16..f7241d1 100644 --- a/src/React/Basic/DOM/Events.purs +++ b/src/React/Basic/DOM/Events.purs @@ -102,7 +102,7 @@ nativeEvent = unsafeEventFn \e -> (unsafeCoerce e).nativeEvent preventDefault :: EventFn SyntheticEvent SyntheticEvent preventDefault = unsafeEventFn \e -> unsafePerformEffect do - _ <- (unsafeCoerce e).preventDefault + _ <- propagateThis (unsafeCoerce e).preventDefault e pure e isDefaultPrevented :: EventFn SyntheticEvent Boolean @@ -111,7 +111,7 @@ isDefaultPrevented = unsafeEventFn \e -> unsafePerformEffect do stopPropagation :: EventFn SyntheticEvent SyntheticEvent stopPropagation = unsafeEventFn \e -> unsafePerformEffect do - _ <- (unsafeCoerce e).stopPropagation + _ <- propagateThis (unsafeCoerce e).stopPropagation e pure e isPropagationStopped :: EventFn SyntheticEvent Boolean @@ -207,3 +207,5 @@ clipboardData = unsafeEventFn \e -> toMaybe (unsafeCoerce e).clipboardData -- \ Composition Events compositionData :: EventFn SyntheticEvent (Maybe String) compositionData = unsafeEventFn \e -> toMaybe (unsafeCoerce e).data + +foreign import propagateThis :: forall f t a. f -> t -> Effect a