npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thefoxjob/js-mixin

v1.0.0

Published

Mixin utilities

Downloads

3

Readme

Js Mixin

An adaptation of Justin Fagnani's mixwith.js package.

Please make sure to read the original author's great article on "Real" Mixins with JavaScript Classes, before attempting to use the components offered in this package.

Content

Motivation

At the time of writing this, the original author's mixwith.js package appeared to be no longer maintained. Like many other developers, I too was relying on the mixwith package. However, I did encounter a small defect, which was blocking me from completing some work. An issue was submitted (https://github.com/justinfagnani/mixwith.js/issues/27), yet unfortunately the author remained silent. I assume that Justin simply did not have time to look at it and other opened issues.

With this mind, please note that this package is by no means an attempt to discredit the original author and that he should be acknowledged for his great work. This package is merely an adaptation of the original source.

It is my hopes that Justin will someday return to the mixwith package. If or when that becomes relavant, then this package will be subject to change, in that the core components will be changed to act as wrappers for the original implementation - or at least as much as possible.

Core Differences

The core differences between the original source and this adaptation, is that the package's overall structure has been split into smaller components, each in their own file. Furthermore, all components are exported as JavaScript es6, without any bundling (e.g. no babel / webpack dist exports!).

The functionality of declaring mixins and how to use them remains the same. This is illustrated in the following sections.

How to use

Declaring a mixin

You can declare a mixin via the DeclareMixin method. It will ensure that you can perform instance of checks, if such is required.


import { DeclareMixin } from '@vestergaard-company/js-mixin';

export default DeclareMixin((superClass) => class WidthAware extends superClass {

    set width(width) {
        // Not shown...
    }

    get width() {
        // Not shown...
    }
});

Using a mixin

To apply your custom mixin, use the mix method, just like the original mixwith.js source.


import WidthAware from './MyMixins/WidthAware';
import mix from '@vestergaard-company/js-mixin';

class Box extends mix(class {}).width(
    WidthAware
){
    // Your class implementation...
}

export default Box;

Using multiple mixins

You can of course also apply multiple mixins, using the same method.


import WidthAware from './MyMixins/WidthAware';
import HeightAware from './MyMixins/HeightAware';
import PriceAware from './MyMixins/PriceAware';
import mix from '@vestergaard-company/js-mixin';

class Box extends mix(class {}).width(
    WidthAware,
    HeightAware,
    PriceAware
){
    // Your class implementation...
}

export default Box;

Further Documentation

As mentioned earlier, please review the "Real" Mixins with JavaScript Classes article and the original source. They contain a detailed explanations on how all of this works and why.

License

This package has been released under GPL-3.0. Note: the original source is licenced under Apache-2.0, copyrighted by Justin Fagnani.