mixin-util
A mixin utility for ES2015 Classes
Basic usage
The function accepts the names of mixins or mixin fnctions
const mixinUtil = ; 'settings' 'middleware' { // nothing will work if super is not called super; } let mcc = ; mcc; // log -> worksconsole;
Mixins
Middleware
this mixin adds middleware functionality similar to that of express.
.use
This method will add functions to the middleware stack. Any arrays passed will be flattened. For eaxmple,
;
... is the same as...
;
Error handling middleware ware should accept and error, the expected arguments, and then next. To forward and error to the error handler simply pass it to the next function or throw the error.
.handle
This method will exacute the middleware stack. It accepts the arguments to be passed to the middle functions.
Example:
const mixinUtil = ; 'middleware' { super; } let middle = ; middle; middle; middle; middle; // call stackmiddle;
Settings
This mixin adds setting functionality. For Each of these methods the instance methods applies to the instance and the static method applies to the prototype.
.set
This method accepts the name of the setting and the new value
.get
This method accepts the name of the setting and returns the value of that setting
// returns 'works'
.Setter
This method will assign a setter to a setting. The setter function should accept a value and return the transformed value.
;
.Getter
This method will assign a getter to a setting. You can think of a getter as a imaginary setting. The getter function should accept a object containing all of the settings.
// Settings -> {// name: {// first: 'john',// last: 'doe',// }// } ;
Mixin Pattern
{ // private variables let _private = Symbol"private"; { super; this_private = "hi"; } return MyMixin}