You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrap selector-observer to add AbortSignal, better types, etc #5874
👆 this piece of code covers 2 of the points I suggested.
Also that reminded of another thing I wanted:
automatic class generation and exclusion from the selector
Also in the future it’d be good to extend attachElements with an observe: true option that queries the selector via selector-observer instead of select.all, but that’s unrelated to this change.
Sorry if I'm being misleading, "only run once" means for each element, so if we only use add there's no behavior difference from initialize. Though I digged in GitHub's code and they use both (initialize or just add).
Also, it seems GitHub never teardown their selector-observers?
Honestly I wonder if we should just drop the library and look for alternatives. I feel that having to add the class only to avoid a new call nullifies any speed improvements we get from using the library (if any at all). Also the lib is dead.
Alternatives:
different library?
go full MutationObserver in the end (childTree: true 🥲)
come up with an animationend-based solution (we add a 1ms animation the selector + listen to the event globally and catch its target)
If it really is this simple and efficient, Refined GitHub (and other extensions) could become an order or magnitude easier to manage. Imagine making every feature "declarative" this way, no more wonky listeners.
We can start by adding the CSS to our CSS files for now and maybe later wrap it all in a helper that generates the CSS rules as well as the listener. The only drawback of a dynamic CSS generator is that the CSS would need to be inserted as a literal style tag in the document, but that's not something we need to deal with right now.
Mind a PR? Would be great to see it working on a feature that already uses observe. The problem with the style tag is that it introduces some complexity to this code1 which could save for later, but that's up to you
Footnotes
they start to pile up in the head after multiple navigations, whereas the static CSS wouldn't — but that wouldn't actually cause any bugs ↩
Uhm it’s a bit early to put code I imagined and wrote onto npm before knowing whether it works and what its limitations are (because I know it won’t work on every website)
Uhm it’s a bit early to put code I imagined and wrote onto npm before knowing whether it works and what its limitations are (because I know it won’t work on every website)
I am sorry for this 😔 but I do want to clarify the first prototype I posted here is done separately (and slightly different).
I'm excited because I really love this idea and am gonna use it a lot. You nailed it here:
If it really is this simple and efficient, Refined GitHub (and other extensions) could become an order or magnitude easier to manage. Imagine making every feature "declarative" this way, no more wonky listeners.
I've since incorporated the awesome improvements in #5886 into my library, credits to you ✨
Activity
kidonng commentedon Jul 31, 2022
Actually, this already exists in
selector-observer, same as:initializeis supposed to only run once, but unfortunately it is still haunted by josh/selector-observer#30 so we can't drop thosergh-*classes.fregante commentedon Jul 31, 2022
I only suggested an API change, not a behavior change:
👆 this piece of code covers 2 of the points I suggested.
Also that reminded of another thing I wanted:
Also in the future it’d be good to extend
attachElementswith anobserve: trueoption that queries the selector viaselector-observerinstead ofselect.all, but that’s unrelated to this change.kidonng commentedon Jul 31, 2022
Sorry if I'm being misleading, "only run once" means for each element, so if we only use
addthere's no behavior difference frominitialize. Though I digged in GitHub's code and they use both (initializeor justadd).Also, it seems GitHub never teardown their
selector-observers?kidonng commentedon Jul 31, 2022
Found an example how GitHub uses
AbortControllerwithselector-observer:fregante commentedon Jul 31, 2022
Honestly I wonder if we should just drop the library and look for alternatives. I feel that having to add the class only to avoid a new call nullifies any speed improvements we get from using the library (if any at all). Also the lib is dead.
Alternatives:
animationend-based solution (we add a 1ms animation the selector + listen to the event globally and catch itstarget)kidonng commentedon Jul 31, 2022
GitHub is still happily using it unmodified 🤷♂️ I think the lib is fine, it's just different expectations (anything may throw in our case).
That's neat but if there are hundreds of elements, does it impact speed?
fregante commentedon Jul 31, 2022
This is by far the most efficient, it has 3 parts:
animationendis triggered even with an empty@keyframes lol {}, which means it doesn't trigger layout/render operationsThe best part is that the animation name (
keyframes) is part of the event itself, so all we need is something like:If it really is this simple and efficient, Refined GitHub (and other extensions) could become an order or magnitude easier to manage. Imagine making every feature "declarative" this way, no more wonky listeners.
We can start by adding the CSS to our CSS files for now and maybe later wrap it all in a helper that generates the CSS rules as well as the listener. The only drawback of a dynamic CSS generator is that the CSS would need to be inserted as a literal
styletag in the document, but that's not something we need to deal with right now.kidonng commentedon Jul 31, 2022
I also made one:
fregante commentedon Jul 31, 2022
🔥
Mind a PR? Would be great to see it working on a feature that already uses
observe. The problem with thestyletag is that it introduces some complexity to this code1 which could save for later, but that's up to youFootnotes
they start to pile up in the head after multiple navigations, whereas the static CSS wouldn't — but that wouldn't actually cause any bugs ↩
kidonng commentedon Jul 31, 2022
Return a cleanup function to remove the style element 😂
I agree static CSS is better, but that needs to write a
separatorseparate generator, while this works anywhere.fregante commentedon Jul 31, 2022
The only issue I see with static CSS is that:
fregante commentedon Jul 31, 2022
Are you referring to the class name? It doesn’t need to be generated, as shown in my example. It would be convenient and ideal, but not required.
cheap-glitch commentedon Jul 31, 2022
Love the
animationendhack!I wonder how hard it'd be to write a Webpack (or maybe PostCSS) plugin to generate the required CSS at build time 🤔
kidonng commentedon Jul 31, 2022
fregante commentedon Aug 1, 2022
Uhm it’s a bit early to put code I imagined and wrote onto npm before knowing whether it works and what its limitations are (because I know it won’t work on every website)
fregante commentedon Aug 3, 2022
See #5886 (comment)
This is why I wanted to keep things simple for a first pass, it was an experimental idea and it turns out it's not safe to use.
Will have to revert to the original scope:
selector-observerkidonng commentedon Aug 16, 2022
I am sorry for this 😔 but I do want to clarify the first prototype I posted here is done separately (and slightly different).
I'm excited because I really love this idea and am gonna use it a lot. You nailed it here:
I've since incorporated the awesome improvements in #5886 into my library, credits to you ✨