Skip to content

Commit

Permalink
feat(): assume NodeList
Browse files Browse the repository at this point in the history
fromEvent() now assumes it is passed a NodeList and creates
a single stream from all of the elements of a NodeList.

Closes #17
  • Loading branch information
TylorS committed Dec 10, 2015
1 parent 047383d commit 503652d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/fromEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Stream from 'most/lib/Stream'
import MulticastSource from 'most/lib/source/MulticastSource'
import forEach from 'fast.js/array/forEach'

const tryEvent =
(t, x, sink) => {
Expand Down Expand Up @@ -40,12 +41,17 @@ EventAdapter.prototype.dispose = function dispose() {

const initEventTarget =
(source, event, addEvent, useCapture) => { // eslint-disable-line
source.addEventListener(event, addEvent, useCapture)
forEach(
source,
s => s.addEventListener(event, addEvent, useCapture)
)

const dispose =
(_event, target) => {
target.removeEventListener(_event, addEvent, useCapture)
}
const dispose = (_event, target) => {
forEach(
target,
t => t.removeEventListener(_event, addEvent, useCapture)
)
}

return dispose
}
Expand All @@ -70,7 +76,7 @@ EventTargetSource.prototype.run = function run(sink, scheduler) {
const fromEvent =
(event, source, useCapture = false) => {
let s
if (source.addEventListener && source.removeEventListener) {
if (source[0].addEventListener && source[0].removeEventListener) {
s = new MulticastSource(
new EventTargetSource(event, source, useCapture)
)
Expand Down

0 comments on commit 503652d

Please sign in to comment.