https://github.com/serapath/eventhandler-stream
Create DOM event handler functions that are streams
https://github.com/serapath/eventhandler-stream
Last synced: 10 months ago
JSON representation
Create DOM event handler functions that are streams
- Host: GitHub
- URL: https://github.com/serapath/eventhandler-stream
- Owner: serapath
- License: mit
- Created: 2015-12-28T14:20:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-12T01:52:26.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T05:50:36.051Z (11 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eventhandler-stream
Create DOM event handler functions that are streams
It supports event filtering
# Example
```html
Click me
```
```js
// index.js
var eventhandlerstream = require('eventhandler-stream')
// EXAMPLE 1
var button = document.querySelector('button')
// A function can be passed as an argument
// 1. It consumes the event
// 2. it filters what's not pushed to the callback `push`
function custom (ev, push) { if (ev.type === 'click') push(ev.type) }
var buttonHandler$ = eventhandlerstream(custom)
button.addEventListener('click', buttonHandler$)
buttonHandler$.on('data', function (eventType) { console.log(eventType) })
// EXAMPLE 2
var vdom = require('virtual-dom')
var h = vdom.h
var create = vdom.create
// If no function is passed it defaults to
// `function custom (ev, push) { push(ev) }`
var linkHandler$ = eventhandlerstream()
linkHandler$.on('data', function (event) { console.log(event) })
var template = h('a', { onclick: linkHandler$ }, '> clickEvent2console <')
document.querySelector('#content').appendChild(create(template))
```
#### Convert `index.js` to `bundle.js` with the help of for example `browserify`
* `npm install browserify -g`
* `browserify index.js > bundle.js`