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

mixin-decorator-with-symbols

v0.0.1

Published

A decorator for mixins that doesn't overwrite existing methods

Downloads

3

Readme

Mixin Decorator with Symbols:

This is a modification ( fork) of the Mixin Decorator with all its initial README.md listed below.

This version adds the ability for mixin behaviors to have Symbols as keys instead of only strings.

This modification was made as a pull request to the original library. Pending that request, I have published this library here.

Meanwhile, thanks to crossman for building this in the first place.

Otherwise, please refer to the original documentation below.

Mixin Decorator

Build Status Package Version

This is a simple decorator function for mixing in behaviors from other sources. It can be called multiple times or passed multiple behaviors. It is useful for React components because it allows multiple definitions of the same method for methods that return undefined. So you can have mixins that tap into the component lifecycle without breaking each other.

Installation

npm install -S mixin-decorator

Examples

// behaviors/hello.js
const hello = {
  hello(){
    console.log("hello world")
  }
}

export default hello
import mixin from "mixin-decorator"
import hello from "./behaviors/hello.js"

@mixin(hello)
class Hello{
}

var obj = new Hello()
obj.hello() //output: hello world

Using mixin-decorator with React Components

mixin-decorator let's multiple mixins declare the same method. This is great for letting mixin's tap into React's lifecycle.

import React from "react"
import mixin from "mixin-decorator"

const behavior1 ={
  componentDidMount(){
    console.log("behavior1 tapped into componentDidMount")
  }
}

const behavior2 ={
  componentDidMount(){
    console.log("so did behavior2")
  }
}

@mixin(behavior1, behavior2)
class MyComponent extends React.Component {
  componentDidMount(){
    console.log("i'm a component")
  }

  render(){
    return <div>Hello</div>
  }
}

When MyComponent is mounted the console would have 3 logs:

i'm a component
behavior1 tapped into componentDidMount
so did behavior2

Documentation

@mixin(...behaviors)

It accepts one or more objects full of behaviors to mix in. If your mixins have definitions of the same method and you care about the order they are called in, use this style as they will be called in the order specified.

@mixin(helloWorld, edit)
class Hello {

It can also be stacked. If your mixins declare the same method be aware that they will be called in reverse order when using this style. This is because it is equivalent to this mixin(edit)(Hello); mixin(helloWorld)(Hello)

@mixin(helloWorld)
@mixin(edit)
class Hello {