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.
@elmsln @haxcamp @btopro #HAXTheWeb #drupal #webcomponents #edtech ✻ Full stack unicorn
Adjunct professor teaching about webdev, ethics, and everything in between
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 :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.Nice, I didn't have a convention for this as I've only written a few general purpose
SuperClass
. Renaming toIntersectionObserverMixin
, I like that better :)