-
Notifications
You must be signed in to change notification settings - Fork 295
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
[Proposal] Avoid the need of the MutationObserver callback #1019
Comments
Hey, thanks for contributing your idea. I find the arguments against the current approach a little hard to follow. It also seems to me that using async iterators would incur some overhead as well as result in some delay due to promises. Having said that, if this were an extremely popular way to consume node tree mutations I could be persuaded to add an API for it. Have you developed this into a library for people to use? |
FWIWI ...
I've implemented MO in LinkeDOM and used to polyfill for years and never needed this pattern which I am struggling to understand what is useful for ... it just keeps accumulating mutations, growing the heap, running these late, plus if the proposed code works, seems like an ad-hoc user-land use case that can be addressed, definitively not what I'd like to have instead of the current MO? |
Thanks for your feedback. I will try to detail a bit my arguments but, to be honest, the explanations aren't my best skill. Don't hesitate to ask if something remains opaque. In a few words, the most problem is the unidirectional side of the callback.
An enclosing function implies 2 major problems:
Alternatively to the previous point, a solution can be to have something like a Pub/Sub to push the records but:
Since an observer can observe more than one target, if we want to some tasks on a specific target, we only have 2 choices:
observer.observe(target, options)
for await (const record of observer) {
if (record.target !== target) {
continue
}
// do something with the record
} Using an async iterator, we can simplify all of these points, preserve the immutability if needed, we can retrieve the records externally and do the tasks in any order, without the need to create a manager, keeping the things easily maintainable . Having said that, I agree with @WebReflection about the growing heap, it's probably a bad idea, I didn't think about it... a better idea is maybe to make an unique iterator, using a |
Oh, and, no, I haven't done a library yet using these features but maybe a day, it will probably depend on the pros/cons raised in this discussion.... I'm still a bit busy on my immutable & JS-typed things, actually... I just made it, for the PoCs, due to a usecase needed to help on TCD... it was a funny thing to make. :P |
Thanks. I think in that case this kind of thing is better left to userland for now. There's two main reasons to add something to a web platform standard in my view:
|
Imho, it simplify the developer ergonomics but, ok, no worries. :) |
Perhaps, but adoption as a popular library is important to demonstrate that as well. |
I see, I see, I'm working a lot to make some innovative solutions but I can't afford to make them popular. ^^' |
Hi all,
I would like to suggest an improvement on the
MutationObserver
.Motivations
Imho, the current implemetation has a problem increasing the code complexity: the need of to treat the mutations in a callback.
Depending on the strategies...
The suggested improvement
An idea I implemented to simplify the behavior is to turn the observer as an iterable.
My approach, to see the suggested behavior:
Usage
Any thoughts about it, please?
The text was updated successfully, but these errors were encountered: