Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active April 24, 2020 12:56
Show Gist options
  • Save NyaGarcia/953ffc30b265000beeecdf3fbeb3e217 to your computer and use it in GitHub Desktop.
Save NyaGarcia/953ffc30b265000beeecdf3fbeb3e217 to your computer and use it in GitHub Desktop.
Creating Observables with the fromEvent() function
import { fromEvent } from "rxjs";
import { map } from 'rxjs/operators';
// Creating an Observable from mouse clicks
const click$ = fromEvent<MouseEvent>(document, "click");
// Creating an Observable from pressed keys
const keyPressed$ = fromEvent<KeyboardEvent>(document, "keydown");
// Creating an Observable from scroll changes
const scroll$ = fromEvent<UIEvent>(document, "scroll");
// Creating an Observable from copy action
const copie$ = fromEvent<ClipboardEvent>(document, "copy");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment