-
Notifications
You must be signed in to change notification settings - Fork 0
Event
Eugene Ghanizadeh edited this page Oct 21, 2021
·
5 revisions
function event(node: EventTarget, name: string, options?: boolean | AddEventListenerOptions): Source<Event>
Listens to specified DOM events on given HTML element, and emits them.
HTML Code
<button>Click Me!</button>
<div></div>
import { pipe, event, scan, observe, tap } from 'streamlets'
const button = document.querySelector('button')
const div = document.querySelector('div')
pipe(
event(button, 'click'),
scan(c => c + 1, 0),
tap(count => div.textContent = `Clicked ${count} times.`),
observe
)
💡
event()
also accepts the sameoptions
asaddEventListener()
:pipe( event(window, 'scroll', { passive: true }), // ... )