Wrap `selector-observer` to add `AbortSignal`, better types, etc
See original GitHub issueI recently mentioned this in a comment but I can’t find it anymore. @cheap-glitch also mentioned it in https://github.com/refined-github/refined-github/pull/5726#pullrequestreview-1019332862
Here’s part of what I had in mind for a such a wrapper:
- accept
signal
- use https://github.com/g-plane/typed-query-selector to automatically get types instead of using
constructor
- better API (
observeElement('a', cb)
instead ofobserve('a',{add: cb})
) - more I can’t remember 🥲
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:17 (17 by maintainers)
Top Results From Across the Web
josh/selector-observer: Allows you to monitor DOM ... - GitHub
selector -observer allows you to monitor DOM elements that match a CSS selector. Rather than imperatively querying the DOM, register an observer for...
Read more >Fregante - Twitter
I'd really benefit from having a React and HTML expert one chat away for "best practice" questions. I can't really trust SO answers...
Read more >Can I use... Support tables for HTML5, CSS3, etc - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort ......
Read more >Web Platform Design Principles - W3C
Abstract. This document contains a set of design principles to be used when designing web platform technologies. These principles have been ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is by far the most efficient, it has 3 parts:
animationend
is 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
style
tag in the document, but that’s not something we need to deal with right now.I put my code into a package 👉 https://github.com/kidonng/animation-observer
It’s very simple but should do the work™️ you are welcome to try.