Giter Club home page Giter Club logo

pull-dom-events's Introduction

pull-dom-events

Simple pull-stream for DOM events

Install

npm install --save pull-dom-events

Usage

const pull = require('pull-stream')
const {pullEvent, click} = require('pull-dom-events')
const {log, filter} = pull

pull(
    pullEvent('click', document),
    filter(event => event.target.matches(...)),
    log()
)

// or shorthand method

pull(
    click(document),
    filter(event => event.target.matches(...)),
    log()
)

pullEvent(eventType, element, capture?)

pullEvent takes a eventType such click, mouseover, keydown, etc an element such as document and an optional capture boolean.

eventType(element, capture?)

eventType takes a element to bind to and an option capture boolean

Currently supporting the following event-types:

click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseenter, mouseout, mouseleave, keydown, keypress, keyup, load, unload

 const source = click(document)

Todo

  • more tests
  • more shorthand event types

pull-dom-events's People

Contributors

davidchase avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

pull-dom-events's Issues

be a well-behaved pull-stream

If the sink always reads synchronously, this module should work fine,
however in some situations it will behave in correctly.

https://github.com/davidchase/pull-dom-events/blob/master/index.js#L7

If an event happens more than once before the sink has read again, it will call the callback twice.
(but with a new value)

There are different ways you could address this, depending on what behavior you want with dom events, but the simplest thing would be to unset callback before calling it.

if(callback) {
  let _cb = callback
  callback = null
  _cb(err, data)
}

then you know callback can never be called twice, even if it's called recursively (before itself has returned)

Another question is what do do about events that happen inbetween calls?
one idea would be to let them drop, so you could have a stream of mousemove events,
and whenever you call read you get either the most recent or the next mouse event.
If you just implement the above suggestion, you'll always get the next mouse event.

you could also keep the most recent event, and respond with that if it hasn't been read yet.

for keyboard events you might want to keep the sequence of events?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.