mix-into
Mix objects into other objects
Last updated 13 years ago by scottcorgan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install mix-into 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.4.0                                ...           latest (13 years ago)

7 Versions

  • 0.4.0                                ...           13 years ago
  • 0.3.1                                ...           13 years ago
  • 0.3.0                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 12
Today 0
This Week 7
This Month 12
Last Day 2
Last Week 5
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE