Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Breaking changes:
- Migrate FFI to ES modules (#24 by @JordanMartinez)

New features:
- Add `addEventListenerWithOptions` to expose more options (#25 by @JordanMartinez)

Bugfixes:

Expand Down
12 changes: 12 additions & 0 deletions src/Web/Event/EventTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ export function eventListener(fn) {
};
}

export function addEventListenerWithOptions(type) {
return function (listener) {
return function (options) {
return function (target) {
return function () {
return target.addEventListener(type, listener, options);
};
};
};
};
}

export function addEventListener(type) {
return function (listener) {
return function (useCapture) {
Expand Down
16 changes: 16 additions & 0 deletions src/Web/Event/EventTarget.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Web.Event.EventTarget
, EventListener
, eventListener
, addEventListener
, addEventListenerWithOptions
, removeEventListener
, dispatchEvent
) where
Expand All @@ -29,6 +30,21 @@ foreign import eventListener
. (Event -> Effect a)
-> Effect EventListener

-- | Adds a listener to an event target.
-- | - `capture` - whether the listener is added to the "capture" phase
-- | - `once` - if true, indicates listener should be invokved at most once
-- | before being automatically removed.
-- | - `passive` - indicates the callback function will never call `preventDefault`
foreign import addEventListenerWithOptions
:: EventType
-> EventListener
-> { capture :: Boolean
, once :: Boolean
, passive :: Boolean
}
-> EventTarget
-> Effect Unit

-- | Adds a listener to an event target. The boolean argument indicates whether
-- | the listener should be added for the "capture" phase.
foreign import addEventListener
Expand Down