sindresorhus/element-ready

Subscribe to new elements on the page #22

fregante posted onGitHub

elementReady only works for one element, but sometimes it’s useful to just get all the elements on the page as they load. For example:

elementReady.subscribe('a', shortenLink);

This will run the function on each new element found on the page before reaching DOM ready.

MutationObserver with subtree:true would be ideal for this but somewhere at some point I read that it’s heavy to run this while the page loads as there are too many events. It would be great to actually test this and compare it to a simpler setInterval + querySelectorAll. Without performance tests, I’d avoid MutationObserver


Note: This issue has a bounty, so it's expected that you are an experienced programmer and that you give it your best effort. Don't forget, if applicable, to add tests, docs (double-check for typos), and update TypeScript definitions. Instead of asking too many questions, present solutions. The point of an issue bounty is to reduce my workload, not give me more. Thanks for helping out 🙌


Should it support the same options as elementReady()?

posted by sindresorhus almost 6 years ago

I guess they’d make sense here as well

posted by bfred-it almost 6 years ago

@issuehunt has funded $80.00 to this issue.


posted by issuehunt-app[bot] almost 6 years ago

I would gladly work on this if no one's working on it...

posted by qti3e almost 6 years ago

Eventually I found this: https://github.com/josh/selector-observer

It's what GitHub uses. It's built around MutationObserver with various optimizations on top of it. Its performance might not be super (https://bugzilla.mozilla.org/show_bug.cgi?id=1422522) but it seems to work well enough for GitHub.

I really wish this was a native API

posted by fregante almost 5 years ago

If anyone wants to work on this, see the previous attempt and feedback in https://github.com/sindresorhus/element-ready/pull/24.

posted by sindresorhus over 4 years ago

What web content should I use to test the performance of MutationObserver vs setInterval + querySelectorAll while loading?

posted by Richienb over 4 years ago

@sindresorhus has rewarded $72.00 to @richienb. See it on IssueHunt

  • :moneybag: Total deposit: $80.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $8.00
posted by issuehunt-app[bot] over 2 years ago

Fund this Issue

$80.00
Rewarded

Rewarded pull request

Other pull requests

Recent activities

richienb was rewarded by sindresorhus for sindresorhus/element-ready# 22
over 2 years ago
richienb submitted an output to  sindresorhus/ element-ready# 22
over 3 years ago