Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Creation Operator for Mutation Observer #5002

Closed
niklas-wortmann opened this issue Sep 6, 2019 · 1 comment
Closed

New Creation Operator for Mutation Observer #5002

niklas-wortmann opened this issue Sep 6, 2019 · 1 comment
Labels
feature PRs and issues for features

Comments

@niklas-wortmann
Copy link
Member

I think it would be very valuable to have a creation operator for an Observable of a Mutation Observer. It used to be in rxjs-dom already but wasn't ported. I think it allows really cool and reactive ui architectures.
Rough idea: The observable is is for example triggered as soon as there is a child element added to the dom. With the trigger within the observable one could initiate a loading indicator or do some optimistic ui update, while fetching some data from an HTTP server or whatever. Thinks like endless scrolling would be amazing to implement with such an approach.

From an api perspective, I'm unsure whether it would be better to have a creation operator that accepts a mutation observer instance or just the needed parameter.

What do you think of that idea?

@A-Babin
Copy link

A-Babin commented Dec 27, 2019

MutationObserver shares a mostly similar interface with IntersectionObserver and ResizeObserver. The latter two are currently at the working and editors draft stage respectively and don't have full browser support yet, but it may be worthwhile to have an creation operator that works with all three. I've already used my own Mutation Observable to great effect in Chrome extensions, but I expect that Intersection and Resize will end up seeing more general use.

They all (unfortunately) require the handler on construction so I don't know how creating with instances would work in any case. Perhaps something like this:

type DOMObservableType = "mutation" | "resize" | "intersection";

type DOMObservableOptions = {
  mutation : MutationObserverInit,
  resize : {box ?: "content-box" | "border-box"},
  intersection: {
    root ?: Element,
    rootMargin ?: string,
    threshold ?: number
  }
}

type DOMObservableEntry = {
  mutation : MutationRecord[],
  resize : ResizeObserverEntry[] // Not in DOM type library yet
  intersection : IntersectionObserverEntry[]
}

function fromDOM<T extends DOMObservableType>(
    type : T, 
    target : Element, // Iterable<Element> ? 
    options ?: DOMObservableOptions[T]
  ) : Observable<DOMObservableEntry[T]>{ // Maybe pass the observer instance too like the native callbacks do
  //...
}

There's also PerformanceObserver and ReportingObserver.

@benlesh benlesh closed this as completed May 4, 2021
@ReactiveX ReactiveX locked and limited conversation to collaborators May 4, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feature PRs and issues for features
Projects
None yet
Development

No branches or pull requests

3 participants