Sha256: 4c19a70308a1fbed1af2e149ba9c76c470233445090ab1d403de02c3e72446bb
Contents?: true
Size: 1.23 KB
Versions: 5
Compression:
Stored size: 1.23 KB
Contents
/* vim:set ts=2 sw=2 sts=2 expandtab */ /*jshint asi: true undef: true es5: true node: true browser: true devel: true forin: true latedef: false globalstrict: true */ "use strict"; var reducible = require("reducible/reducible") var isReduced = require("reducible/is-reduced") function open(target, type, options) { /** Capture events on a DOM element, converting them to a reducible channel. Returns a reducible channel. ## Example var allClicks = open(document.documentElement, "click") var clicksOnMyTarget = filter(allClicks, function (click) { return click.target === myTarget }) **/ var capture = options && options.capture || false return reducible(function reducDomEvents(next, result) { function handler(event) { result = next(event, result) // When channel is marked as accumulated, remove event listener. if (isReduced(result)) { if (target.removeEventListener) target.removeEventListener(type, handler, capture) else target.detachEvent(type, handler, capture) } } if (target.addEventListener) target.addEventListener(type, handler, capture) else target.attachEvent("on" + type, handler) }) } module.exports = open
Version data entries
5 entries across 2 versions & 1 rubygems