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:
;
mixins has 3 arguments
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.
{ ; }
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:
; // The first class to be used as a mixin { console; } { console; } // The second class to be used as a mixin { console; } { ; // outputs 'test Method 1 from TestMixin2' and then 'test Method 1 from TestMixin1' will warn in console about duplicate methods. }
Mixing in a function:
; // A function to add as a mixin{ console;} { ; // outputs 'test function' }