RxJS provides some functions for creating Observable objects. We can create Observable objects based on events, timers, Promise, AJAX, etc.
Below are a few examples of creating Observable objects based on events.
this.outsideClick$ = fromEvent(document, 'click').subscribe((event: MouseEvent) => {
this.onClick(event);
});
fromEvent(window, 'resize').subscribe((e: any) => {
this.windowSize = e.target.innerWidth;
}),
fromEvent(document, 'mousedown').subscribe((event) => {
if (!event['isOpen']) {
this.close(null);
}
}),
fromEvent(window, 'mousewheel').pipe(
debounceTime(250)
).subscribe((e: any) => {
// handle e
}
}),