Evt.from<T>(...)
Returns
Parameters
Examples
With DOM EventTarget
From ResizeObserver
From EventEmitter
With RxJS Subject
With JQuery-like event target
Last updated
Was this helpful?
Was this helpful?
import { Evt } from "evt";
Evt.from(document, "click").attach(mouseEvent=> {/*...*/});
const ctx = Evt.newCtx();
Evt.from(ctx, document, "wheel").attach(wheelEvent=> {/*...*/});declare const htmlButtonElement: HTMLButtonElement;
Evt.from(ctx, htmlButtonElement, "click").attach(mouseEvent => {/* ... */});const ctx = Evt.createCtx();
declare const htmlDivElement: HTMLDivElement;
Evt.from(ctx, ResizeObserver, htmlDivElement).attach(resizeObserverEntry=>{/* ... */});import { Evt } from "evt";
import { EventEmitter } from "events";
const ctx= Evt.newCtx();
const ee= new EventEmitter();
const evtText= Evt.from<string>(ctx, ee, "text");
evtText.attach(text=> console.log(text));
evtText.post("Foo bar");//Prints "Foo bar";
ctx.done();
console.log(ee.listenerCount("text"));//Prints "0"import { Evt } from "evt";
import { Subject } from "rxjs";
const ctx= Evt.newCtx();
const subject = new Subject<string>();
const evtText = Evt.from(ctx, subject); //The type argument is inferred.
evtText.attach(text=> console.log(text));
subject.next("Foo bar"); //Prints "Foo bar"
ctx.done();
subject.next("Foo bar"); //Prints nothingimport { Evt } from "evt";
Evt.from([
$("#btnA"),
$("#btnB"),
$("#btnC")
], "click").attach(()=> console.log("Clicked!"));