{"_id":"mixwith","_rev":"8-86de4d45d9207099566d47bc89e1e0ca","name":"mixwith","description":"A simple, powerful mixin applier for JavaScript classes","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"mixwith","version":"0.1.0","description":"A simple, powerful mixin applier for JavaScript classes","main":"mixwith.js","directories":{"test":"test"},"dependencies":{},"devDependencies":{"babel-plugin-transform-es2015-modules-umd":"^6.1.18","chai":"^3.4.1","event-stream":"^3.3.2","gulp":"^3.9.0","gulp-babel":"^6.1.0"},"scripts":{"test":"mocha build/test","build":"gulp"},"repository":{"type":"git","url":"git+https://github.com/justinfagnani/mixwith.js.git"},"keywords":["mixin","mixins","classes"],"author":{"name":"Jusitn Fagnani","email":"justin@fagnani.com"},"license":"Apache-2.0","bugs":{"url":"https://github.com/justinfagnani/mixwith.js/issues"},"homepage":"https://github.com/justinfagnani/mixwith.js#readme","gitHead":"2cd2f414ab54344b60ab3d22f3cad393d5e21659","_id":"mixwith@0.1.0","_shasum":"dc8763d41ee8f4853a95dbe4df5b933369f6350f","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"justinfagnani","email":"justin@fagnani.com"},"dist":{"shasum":"dc8763d41ee8f4853a95dbe4df5b933369f6350f","tarball":"https://registry.npmjs.org/mixwith/-/mixwith-0.1.0.tgz","integrity":"sha512-1cYlrhK4nCpY/gXxDEJ1ZaRlGl/qFwE4Q20CyNzu6cocfEVhMhx17nertB/qw+hvwOGGn6rCx7vD26SmuJtCaw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC73JwT5YTPN2aBje6L3kzPxmhCcPfZxojWsiF5p+AzBgIhAJbXTOxFXFMy+1PoO1nYA5ubJFLJeNbW+H1hRBA+PEbe"}]},"maintainers":[{"name":"justinfagnani","email":"justin@fagnani.com"}]},"0.1.1":{"name":"mixwith","version":"0.1.1","description":"A simple, powerful mixin applier for JavaScript classes","main":"mixwith.js","directories":{"test":"test"},"dependencies":{},"devDependencies":{"babel-plugin-transform-es2015-modules-umd":"^6.1.18","chai":"^3.4.1","event-stream":"^3.3.2","gulp":"^3.9.0","gulp-babel":"^6.1.0"},"scripts":{"test":"mocha build/test","build":"gulp"},"repository":{"type":"git","url":"git+https://github.com/justinfagnani/mixwith.js.git"},"keywords":["mixin","mixins","classes"],"author":{"name":"Jusitn Fagnani","email":"justin@fagnani.com"},"license":"Apache-2.0","bugs":{"url":"https://github.com/justinfagnani/mixwith.js/issues"},"homepage":"https://github.com/justinfagnani/mixwith.js#readme","gitHead":"1aef19debcb5a5234553d5923b66fbce2d963e3f","_id":"mixwith@0.1.1","_shasum":"c8995918c5b61fbfda9ad377a857cd47750541c0","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"justinfagnani","email":"justin@fagnani.com"},"dist":{"shasum":"c8995918c5b61fbfda9ad377a857cd47750541c0","tarball":"https://registry.npmjs.org/mixwith/-/mixwith-0.1.1.tgz","integrity":"sha512-DQsf/liljH/9e+94jR+xfK8vlKceeKdOM9H9UEXLwGuvEEpO6debNtJ9yt1ZKzPKPrwqGxzMdu0BR1fnQb6i4A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHhMiymLPHKfz/krB8QLUhkaUeITTbhzZnNyzf+rvjlYAiEAtrIlJVNymk1acWz2HocGJubRJFkNaD8paabXK4CBnws="}]},"maintainers":[{"name":"justinfagnani","email":"justin@fagnani.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/mixwith-0.1.1.tgz_1459062291891_0.29040109808556736"}}},"readme":"# mixwith.js\n\nA simple, powerful and safe mixin library for ES6.\n\n## Overview\n\n`mixwith` differs from other mixin approaches because it does not copy properties from one object to another. Instead, `mixwith` works with \"subclass factories\" which create a new class that extends a superclass with the mixin - this is called a _mixin_ _application_.\n\nSubclass factory style mixins take advantage of two awesome features of ES6 classes: _class_ _expressions_, and expressions in the `extends` clause of a class declaration.\n\n### Quick Example\n\n#### Define a Mixin:\n\n```javascript\nlet MyMixin = (superclass) => class extends superclass {\n  // mixin methods here\n};\n```\n\n#### Use a Mixin without mixwith:\n\n```javascript\nclass MyClass extends MyMixin(MySuperClass) {\n  // class methods here, go ahead, use super!\n}\n```\n\n#### Use a Mixin with mixwith:\n\n```javascript\nclass MyClass extends mix(MySuperClass).with(MyMixin, OtherMixin) {\n  // class methods here, go ahead, use super!\n}\n```\n\n`mixwith` preserves the object-oriented inheritance properties that classes provide, like method overriding and `super` calls, while letting you compose classes out of mixins without being constrained to a single inheritance hierarchy, and without monkey-patching or copying.\n\n### Advantages of subclass factories over typical JavaScript mixins\n\n#### Method overriding that just works\n\nMethods in subclasses can naturally override methods in the mixin or superclass, and mixins override methods in the superclass. This means that precedence is preserved - the order is: _subclass_ -> _mixin__1_ -> ... -> _mixin__N_ -> _superclass_.\n\n#### `super` works\n\nSubclasses and mixins can use `super` normally, as defined in standard Javascript, and without needing the mixin library to do special chaining of functions.\n\n#### Mixins can have constructors\n\nSince `super()` works, mixins can define constructors. Combined with ES6 rest arguments and the spread operator, mixins can have generic constructors that work with any super constructor by passing along all arguments.\n\n#### Prototypes and instances are not mutated\n\nTypical JavaScript mixins usually used to either mutate each instance as created, which can be bad for performance and maintainability, or modify a prototype, which means every object inheriting from that prototype gets the mixin. Subclass factories don't mutate objects, they define new classes to subclass, leaving the original superclass intact.\n\n## Usage\n\n### Defining Mixins\n\nA mixin is simply a function that takes a superclass and returns a subclass of it, using ES6 class expressions:\n\n```javascript\nlet MyMixin = (superclass) => class extends superclass {\n\n  constructor(args...) {\n    // mixins should either 1) not define a constructor, 2) require a specific\n    // constructor signature, or 3) pass along all arguments.\n    super(...args);\n  }\n\n  foo() {\n    console.log('foo from MyMixin');\n    // this will call superclass.foo()\n    super.foo();\n  }\n\n};\n```\n\nMixins defined this way do not require any helpers to define or use. You can use this pattern without `mixwith` at all!\n\n### Using Mixins\n\nWithout `mixwith`, just invoke them inside a classes `extends` clause:\n\n```javascript\nclass MyClass extends MyMixin(MySuperClass) {\n}\n```\n\n`mixwith` provides a helper that's a bit nicer when applying multiple mixins, and adds some features like mixin-deduplication and `@@hasInstance` support (`@@hasInstance` overloads `instanceof`, but isn't supported in any browsers yet).\n\n```javascript\nclass MyClass extends mix(MySuperClass).with(MyMixin) {\n}\n```\n\nClasses that use mixins can define and override constructors and methods as usual.\n\n```javascript\nclass MyClass extends mix(MySuperClass).with(MyMixin) {\n\n  constructor(a, b) {\n    super(a, b); // calls MyMixin(a, b)\n  }\n\n  foo() {\n    console.log('foo from MyClass');\n    super.foo(); // calls MyMixin.foo()\n  }\n\n}\n```\n","maintainers":[{"name":"justinfagnani","email":"justin@fagnani.com"}],"time":{"modified":"2022-06-19T23:07:58.219Z","created":"2015-11-24T01:46:57.088Z","0.1.0":"2015-11-24T01:46:57.088Z","0.1.1":"2016-03-27T07:04:54.190Z"},"homepage":"https://github.com/justinfagnani/mixwith.js#readme","keywords":["mixin","mixins","classes"],"repository":{"type":"git","url":"git+https://github.com/justinfagnani/mixwith.js.git"},"author":{"name":"Jusitn Fagnani","email":"justin@fagnani.com"},"bugs":{"url":"https://github.com/justinfagnani/mixwith.js/issues"},"license":"Apache-2.0","readmeFilename":"README.md","users":{"cortys":true,"fluse":true,"usingthesystem":true,"hallaji":true}}