1.0.1 • Published 10 years ago
dom-delegation-stream v1.0.1
dom-delegation-stream
simple streaming DOM event delegation
example
var events = require('dom-delegation-stream')
var values = require('dom-value-stream')
events(document.body, 'input', 'input[type=text]')
.pipe(values())
.pipe(wherever())API
events(element, eventName, selector, options) -> ReadableStream
- if selector is provided, delegation will be used, otherwise it will not.
- valid options are:
preventDefault <boolean>: will callpreventDefault()on all matched events. Defaults tofalse.stopPropagation <boolean>: will callstopPropagation()on all matched events. Defaults tofalse.useCapture <boolean>: will initiate capture for matched events. Defaults tofalse.
notes
- when using delegation, the element that matches your selector will be
available as
event.delegationTarget. - calling
.end()or otherwise ending the stream returned bydom-delegation-streamwill remove the listeners added for event handling. - there are some alternative options for event handling on npm, a couple that even support delegation, and even some that are streaming. this module was created as an effort to provide a better balance of simplicity and flexibility.
license
MIT