mitsubishi

2.4.0 • Public • Published

mitsubishi

Mixin utilities for extending prototypes

Build Status

Sauce Labs Browser Test Status Sauce Labs Browser Test Status

Install

Node

npm install mitsubishi

Browser

component install mitsubishi
bower install mitsubishi

Usage

mitsubishi.props(class, [classes])

Mixin JUST instance props (not proto props) from Obj literals + Classes.

var myStaticClass = {};
 
/* .mixinInstanceProps() */
mitsubishi.props(myStaticClass, [{hello:true}, {world:true}]);
 
console.log('myStaticClass', myStaticClass);
// outputs: {{hello:true, world:true}

mitsubishi.proto(class, [classes])

Mixin proto props of UNinstantiated Classes (and Obj literals) NOT instance props

var myDynamicClass = function () {};
var parentDynamicClass = function () {};
 
parentDynamicClass.prototype.awesome = blah;
 
mitsubishi.proto(myDynamicClass, [parentDynamicClass, {world:true}]);
 
console.log('myDynamicClass', myDynamicClass);
// outputs: {{awesome:"blah", world:true}

mitsubishi.protoInstantiated(class, [classes])

Mixin proto props of INSTANTIATED Classes (and Obj literals) NOT instance props

var myDynamicClass = function () {};
var parentDynamicClass = function () {};
 
parentDynamicClass.prototype.awesome = blah;
myDynamicClass.hello = true;
 
mitsubishi.protoInstance(myDynamicClass, [(new parentDynamicClass), {world:true}]);
 
console.log('myDynamicClass', myDynamicClass);
// outputs: {{awesome:"blah", world:true, hello:true}

Docs

Yuidocs documentation here

  • fire up the connect server $ grunt docs
  • navigate your browser to the docs

API

mitsubishi

should export all needed API methods.

expect(mitsubishi).to.only.have.keys('proto', 'protoInstantiated', 'props', 'instancePropsFromInstantiated', 'protoPropsFromInstantiated', 'protoPropsFromUninstantiated');
done();
mitsubishi.instancePropsFromInstantiated() - copy instance properties from instantiated dynamic classes as well as object literals.
expect(mitsubishi.instancePropsFromInstantiated({}, [fixtures.A, fixtures.C])).to.only.have.keys('foo', 'bar', 'marbel');
expect(mitsubishi.instancePropsFromInstantiated({}, [fixtures.A, fixtures.B])).to.only.have.keys('foo', 'bar');
expect(mitsubishi.instancePropsFromInstantiated({}, fixtures.A)).to.only.have.keys('foo', 'bar');
expect(mitsubishi.instancePropsFromInstantiated({}, [fixtures.A, (new fixtures.B)])).to.only.have.keys('foo', 'bar', 'blah');
expect(mitsubishi.instancePropsFromInstantiated({}, [(new fixtures.B), fixtures.C])).to.only.have.keys('blah', 'marbel');
 
// doesn't mix in proto props
expect(mitsubishi.instancePropsFromInstantiated({}, (new fixtures.B()))).to.not.have.key('protoproperty');
 
done();
mitsubishi.protoPropsFromInstantiated() - copy poto properties from dynamic classes (if instantiated) as well as object literals.
expect(mitsubishi.protoPropsFromInstantiated({}, [fixtures.A, fixtures.C])).to.have.key('foo', 'bar', 'marbel');
expect(mitsubishi.protoPropsFromInstantiated({}, [(new fixtures.B()), fixtures.C])).to.have.key('marbel');
expect(mitsubishi.protoPropsFromInstantiated({}, (new fixtures.B()))).to.have.key('protoproperty');
 
///////////////////////////////////////////////////////////////////////////////////////////
// MUST BE AN INSTANCE OF A DYNAMIC CLASS
// to add a prototype of an uninstantiated dynamic class then....
// use instancePropsFromInstantiated and....
// directly reference its prototype
/////////////////////////////////////////////////////////////////////////////////////////////
expect(mitsubishi.protoPropsFromInstantiated({}, fixtures.B)).to.not.have.key('protoproperty');
expect(mitsubishi.instancePropsFromInstantiated({}, fixtures.B.prototype)).to.have.key('protoproperty');
// better to use .protoPropsFromUninstantiated()
expect(mitsubishi.protoPropsFromUninstantiated({}, fixtures.B)).to.have.key('protoproperty');
done();
mitsubishi.protoPropsFromUninstantiated() - copy poto properties from dynamic classes (if UNinstantiated) as well as object literals.
// dynamic classes
        var res = function () {};
         mitsubishi.protoPropsFromUninstantiated(res.prototype, fixtures.B);
        expect(res.prototype).to.have.key('protoproperty');
// works with object literals too
        expect(mitsubishi.protoPropsFromUninstantiated({}, fixtures.B)).to.have.key('protoproperty');
        done();

should not copy instance props when using proto methods.

fixtures.B.bull = true;
BInst = new fixtures.B;
BInst.cow = true;
// expect(mitsubishi.protoPropsFromUninstantiated({}, BI)).to.not.have.key('bull');
expect(mitsubishi.protoPropsFromUninstantiated({}, fixtures.B)).to.not.have.key('bull');
expect(mitsubishi.instancePropsFromInstantiated({}, fixtures.B)).to.have.key('bull');
expect(mitsubishi.protoPropsFromInstantiated({}, fixtures.B)).to.not.have.key('bull');
expect(mitsubishi.instancePropsFromInstantiated({}, BInst)).to.have.key('cow');
expect(mitsubishi.protoPropsFromInstantiated({}, BInst)).to.not.have.key('cow');

License

Copyright (c) 2013 Andrew Griffiths mail@andrewgriffithsonline.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.4.0
    0
    • latest

Version History

Package Sidebar

Install

npm i mitsubishi

Weekly Downloads

1

Version

2.4.0

License

MIT

Last publish

Collaborators

  • techjacker