DEV Community

Discussion on: Adding an intersectionObserver to any web component

Collapse
 
dakmor profile image
Thomas Allmer

Nice article 👍 and a very good and real usecase 💪

I think this pattern is usually called a JavaScript Class Mixin 🤔

In our codebase we have a convention and call them what they do + Mixin. e.g. in this case it would probably be ElementVisibleMixin...

Our reasoning for that is:

Why add Mixin? so it's easily find and distinguishable from normal classes.

Why not IntersectionObserverMixin? what you want is to find out if an element is visible - that an Intersection Observer is used is an implementation detail and as a user I should not need to know this.

Collapse
 
btopro profile image
Bryan Ollendyke

Nice, I didn't have a convention for this as I've only written a few general purpose SuperClass. Renaming to IntersectionObserverMixin, I like that better :)