simontonsoftware / s-libs

A collection of libraries for any of javascript, rxjs, or angular.
MIT License
43 stars 5 forks source link

[rxjs-core] Feature request: add `getResize$()` #80

Open ersimont opened 2 years ago

ersimont commented 2 years ago

Add an adapter to get MutationObserver into the rxjs world

export function getResize$(
  target: Element,
  options?: ResizeObserverOptions,
): Observable<ResizeObserverEntry> {
  return new Observable<ResizeObserverEntry>((subscriber) => {
    const observer = new ResizeObserver(([entry]) => {
      subscriber.next(entry);
    });
    observer.observe(target, options);
    return (): void => {
      observer.unobserve(target);
    };
  });
}