flyd-dom-events

1.0.0 • Public • Published

flyd-dom-events

Get DOM events as a Flyd stream

test

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
 *
 */

Package Sidebar

Install

npm i flyd-dom-events

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

5.45 kB

Total Files

5

Last publish

Collaborators

  • neftaly