New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dotmix

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotmix

simple mixin implementation

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Description

Simple mixin implementation.

Latest Version

1.0.1

Installation

npm install dotmix --save

Usage

Add a "mix" method to a source like this:

var Dotmix = require('dotmix');

var Blah = {
  include : function (data) {
    return {
      blah : function (text) {
        return (data.greeting + ' ' + text);
      }
    }
  },
  extend : {
    barf : function (food) {
      return ("NOW BARFING: " + food);
    }
  }
};

Dotmix(Blah);

module.exports = Blah;

Mixin sources should be objects with include and/or extend attributes. Their values can be either an object, or if you want to pass configuration data, functions accepting that single data argument and returning an object.

You mix into a target like this:

var Blah = require('./Blah');

function Barf (derp) {
  this.derp = derp;
}

Blah.mix({
  into : Barf, 
  data : { 
    greeting: 'wow...' 
  }
});

barf = new Barf();
barf.blah('barf!!');   // wow... barf!!
Barf.barf('pancakes'); // NOW BARFING: pancakes

It's also possible to use the Dotmix.mix method directly

var Dotmix = require('dotmix');

var Foo = {
  include : {
    foo : function () {
      return 'food';
    }
  }
};

function Duh (derp) {
  this.derp = derp;
}

Dotmix.mix({
  from : Foo, 
  into : Duh
});

duh = new Duh();
duh.foo() // 'food'

Notes

Includes ideas from

  • "A fresh look at JavaScript Mixins"
  • "The Little Book on CoffeeScript - Classes"

TODO

  • list of mixin sources (probably just subset of npm modules that have "dotmix" as a package.json keyword)

#Build status build status

Keywords

dotmix

FAQs

Package last updated on 26 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts