es6-mixins

WebJar for es6-mixins

License

License

ISC
Categories

Categories

Mixin Application Layer Libs Bytecode Manipulation
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

es6-mixins
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

es6-mixins
WebJar for es6-mixins
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/fender-guy/es6-mixins

Download es6-mixins

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/es6-mixins/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>es6-mixins</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/es6-mixins/
implementation 'org.webjars.npm:es6-mixins:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/es6-mixins/
implementation ("org.webjars.npm:es6-mixins:1.0.2")
'org.webjars.npm:es6-mixins:jar:1.0.2'
<dependency org="org.webjars.npm" name="es6-mixins" rev="1.0.2">
  <artifact name="es6-mixins" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='es6-mixins', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "es6-mixins" % "1.0.2"
[org.webjars.npm/es6-mixins "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ES6 Mixins

An easy way to add mixin methods and functions to your es6 classes and react components.

Installation and Usage:

npm install es6-mixins

Import mixins into your project:

import mixins from 'es6-mixins';

mixins has 3 arguments

mixins([a function, an array, or a class], context, options);

Only the first 2 arguments are required.

  • The first argument can be either a function, an array (containing classes or functions), or a class.
  • The second argument is the context on which to add these methods, if used in the constructor it should be set as this.

The simplest example just adds someFunction to yourClass below.

class YourClass {
	constructor(){
		mixins(somefunction, this);
	}
}

Options Object:

The third argument is an options object that can look like this:

{	
	"warn": true // defaults to true	
	"mergeDuplicates": true // defaults to true
}
  • warn If set to true (default) it will warn you when there are two conflicting methods that aren't react lifecycle methods.
  • mergeDuplicates If set to true (default), this will merge two conflicting methods and call the second one first.

Further Examples:

Mixing in multiple classes:

import mixins from 'es6-mixins';

// The first class to be used as a mixin
class TestMixin1 {
	testMethod1(){
    	console.log('test Method 1 from TestMixin1');
    }
    
    testMethod2(){
    	console.log('test Method 2 from TestMixin2');
    }
}

// The second class to be used as a mixin
class TestMixin2 {
	testMethod1(){
    	console.log('test Method 1 from TestMixin2');
    }
}

class MainClass {
	constructor(){
    	mixins([TestMixin1, TestMixin2], this);
        testMethod1() // outputs 'test Method 1 from TestMixin2' and then 'test Method 1 from TestMixin1' will warn in console about duplicate methods.
    }
}

Mixing in a function:

import mixins from 'es6-mixins';

// A function to add as a mixin
function testFunction(){
	console.log('test function');
}

class MainClass {
	constructor(){
    	mixins(testFunction, this);
        testFunction() // outputs 'test function'
    }
}

Versions

Version
1.0.2