flyd-dom-events
v1.0.0
Published
DOM events as Flyd streams
Downloads
1
Maintainers
Readme
flyd-dom-events
Get DOM events as a Flyd stream
Example
import flyd as 'flyd'
import flydDomEvents as 'flyd-dom-events'
// Add event listeners for mousedown & mouseup on document.body,
// and return a stream of events
const stream = flydDomEvents(
['mousedown', 'mouseup'],
document.body,
{ capture: true }
)
// Log a message every time a mousedown or mouseup event is triggered
flyd.map(
event => console.log(event.type + ' was triggered'),
stream
)
// Remove event listeners & close stream
const destroy = () => stream.end(true)
destroy()
API
/**
* Create a stream of DOM events via addEventListener/removeEventListener
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
*
* @name flydDomEvents
* @param {Array<string>} types - event types
* @param {HTMLElement} target - DOM node to attach listeners to
* @param {Object} [options] - options for addEventListener/removeEventListener
* @return {stream} the DOM event stream
*
*/