Skip to content
Mix objects into other objects
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
README.md
index.js
package.json

README.md

mix-into

Mix objects into other objects.

By adopting the "mix into" methodology, your code avoids the mess of "add this mixin; add this mixin; add this mixin". Istead, you can dynamically nest and defer the the mixin process.

Install

npm isntall mix-into --save

Usage

Basic

var mix = require('mix-into');
var baseMixin = {
  baseValue: 'some value',
  baseMethod: function () {
    return baseValue;
  }
};

var obj = {};

mix(baseMixin).into(obj);

obj.baseMethod(); // OUTPUTS: 'some value'

Partial Applied Mixin

var mix = require('mix-into');
var baseMixin = mix({
  baseValue: 'some value',
  baseMethod: function () {
    return baseValue;
  }
});
var obj = {};

baseMixin.mixInto(obj);

obj.baseMethod() // OUTPUS: 'some value'

Nested Mixins

var mix = require('mix-into');
var baseMixin = mix({
  baseValue: 'some value',
  baseMethod: function () {
    return baseValue;
  }
});

var obj = {
  objMethod: function () {
    return this.baseValue;
  }
};
var obj2 = {};

baseMixin.mixInto(obj);
obj.mixInto(obj2); // mixInto method added to each object that's mixed into

obj2.objMethod() // OUTPUS: 'some value'

Create New Object from Mixin

var mix = require('mix-into');
var baseMixin = mix({
  value1: 'value1'
});

var obj = baseMixin.create();

console.log(obj.value1); // OUTPUTS: 'value1'

Run Tests

npm install
npm test
Something went wrong with that request. Please try again.