UNPKG

995 BTypeScriptView Raw
1import { EventTransformer } from './frombinder';
2import { EventStream } from "./observable";
3export declare type EventSourceFn = (binder: Function, listener: Function) => any;
4/**
5 creates an EventStream from events
6 on a DOM EventTarget or Node.JS EventEmitter object, or an object that supports event listeners using `on`/`off` methods.
7 You can also pass an optional function that transforms the emitted
8 events' parameters.
9
10 The simple form:
11
12 ```js
13 Bacon.fromEvent(document.body, "click").onValue(function() { alert("Bacon!") })
14 ```
15
16 Using a binder function:
17
18 ```js
19 Bacon.fromEvent(
20 window,
21 function(binder, listener) {
22 binder("scroll", listener, {passive: true})
23 }
24 ).onValue(function() {
25 console.log(window.scrollY)
26})
27 ```
28
29 @param target
30 @param eventSource
31 @param eventTransformer
32 @typeparam V Type of stream elements
33
34 */
35export default function fromEvent<V>(target: any, eventSource: string | EventSourceFn, eventTransformer?: EventTransformer<V>): EventStream<V>;