{"name":"react-mixin","version":"1.7.0","description":"![travis](https://travis-ci.org/brigand/react-mixin.svg)","main":"index.js","dependencies":{"object-assign":"^2.0.0","smart-mixin":"^1.2.0"},"devDependencies":{"6to5ify":"^4.0.0","expect.js":"^0.3.1","mocha":"^2.1.0","react":"^0.13.0-beta.1","sinon":"^1.12.2"},"scripts":{"test":"mocha test/*"},"repository":{"type":"git","url":"git+https://github.com/brigand/react-mixin.git"},"keywords":["react","mixin","es6","class","smart-mixin"],"author":{"name":"Frankie Bagnardi","email":"f.bagnardi@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/brigand/react-mixin/issues"},"homepage":"https://github.com/brigand/react-mixin","gitHead":"af33702de8c242d7a21378f1cbf9dbf355f19996","_id":"react-mixin@1.7.0","_shasum":"38c22c3eb02064f08f2c25878a60dac3e956f44c","_from":".","_npmVersion":"2.13.0","_nodeVersion":"0.10.28","_npmUser":{"name":"greenjello","email":"f.bagnardi@gmail.com"},"maintainers":[{"name":"greenjello","email":"f.bagnardi@gmail.com"}],"dist":{"shasum":"38c22c3eb02064f08f2c25878a60dac3e956f44c","tarball":"http://registry-npm.ywwl.com/react-mixin/download/react-mixin-1.7.0.tgz","integrity":"sha512-PZzt6FGoNg2vQPo2pNb84CI0k6s01ZUESHuj1rDTr9ngTvnuMjFmyMibrmpRLyU7enzgbN+vcBfDxX0cXeXIMg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCfRcBS5lol2wXN9S7c59Kj/lhkzPXJpU1hGcNxImJeAAIhAKXfIZoZhEvUh2on7FyA2eSGFtb2jLr+N9ij85Qu5Bm8"}],"size":3768,"noattachment":false,"key":"/react-mixin/-/react-mixin-1.7.0.tgz"},"directories":{},"readme":"![travis](https://travis-ci.org/brigand/react-mixin.svg)\n\n### Note: mixins are basically dead. Only use this as a migration path for legacy code. Prefer [High Order Components](https://facebook.github.io/react/docs/higher-order-components.html).\n\nWant to use ES6/CoffeeScript/TypeScript/{InsertNoun}Script classes, and mixins?\n\nReact doesn't have anything built in for this, but don't worry!  This package implements\nreact's mixin strategy for arbitrary objects.\n\nInstall with one of:\n\n```sh\n# recommended\nnpm install --save react-mixin@2\n\n# will expose window.reactMixin or the reactMixin AMD module\ncurl 'wzrd.in/standalone/react-mixin@2' > vendor/react-mixin.js\n```\n\n\nHere's an example:\n\n```js\nvar reactMixin = require('react-mixin');\nvar someMixin = require('some-mixin');\nclass Foo extends React.Component {\n    render: function(){ return <div /> }    \n}\nreactMixin(Foo.prototype, someMixin);\nreactMixin(Foo.prototype, someOtherMixin);\n```\n\n### Note: Version 5.0 switches to `UNSAFE_`\n\nThe following methods are deprecated in React 16.3.0.\n\n- `UNSAFE_componentWillMount`\n- `UNSAFE_componentWillReceiveProps`\n- `UNSAFE_componentWillUpdate`\n\nIn version `5.0` of this plugin, the previously named `componentWillMount` and friends\nwill no longer behave correctly, and instead `UNSAFE_componentWillMount` must be specified\nin the mixin.\n\nA new utility has been added that can convert a mixin to this format.\n\n```js\nvar reactMixin = require('react-mixin');\nvar toUnsafe = require('react-mixin/toUnsafe');\nvar someMixin = require('some-mixin');\n\nvar fixedMixin = toUnsafe(someMixin);\n\nreactMixin(Foo.prototype, fixedMixin);\n```\n\n---\n\n## Aside: Do I need mixins?\n\n90% of the time you don't need mixins, in general prefer composition via [high order components][hoc-article]. For the 10% of the cases where mixins are best (e.g. PureRenderMixin and react-router's Lifecycle mixin), this library can be very useful.\n\nIf you do need mixins, using this library lets you avoid thinking about the merging of conflicting methods, and other oddities of react's mixin system.\n\n[hoc-article]: https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html\n\n---\n\n\n## Class level behavior\n\nMany of the things that were regular properties in createClass are now static properties of the class.  To have things like getDefaultProps, propTypes, and getInitialState working correctly you need to apply react-mixin a level higher than the prototype: the class itself.\n\n```js\nvar mixin = {\n  getDefaultProps: function(){\n    return {b: 2};\n  }\n};\n\nclass Foo {\n  static defaultProps = {\n    a: 1\n  };\n  render(){\n    console.log(this.props); // {a: 1, b: 2}\n  }\n}\n\nreactMixin.onClass(Foo, mixin);\n```\n\n## But it's at the end of the file!\n\nFor more readability, there is an es7 decorator proposal.  With the latest babel version and the stage config option set to 0 or 1, you can use decorators.\n\n```js\n@reactMixin.decorate(mixin)\nclass Foo {\n  static defa...\n}\n```\n\nNote that this does prototypical inheritance, meaning the returned class is a new class rather than mutating Foo.\n\n## Differences from createClass\n\n@ndout resolved the differences by adding `reactMixin.onClass`.  If there are any more incompatibilites, **other than autobinding methods which is intentionally omitted**, please create an issue.\n\n---\n\nThat's pretty much it.  You get errors instead of silently overwriting things, like in react,\nwith the exception of things whitelisted in index.js as type MANY, MANY_MERGED (getDefaultProps/getInitialState).\n\nAutobinding is done by React.createClass, and there's no equivilent in ES6 classes.  This also has better performance (I think), but you do lose some convenience.  You can explicitly bind things in the constructor or componentWillMount.  On the main class, the constructor replaces componentWillMount.\n\n```js\nclass Foo extends React.Component {\n    constructor(props){\n        super(props);\n        this.handleChange = this.handleChange.bind(this);\n    }\n    ...\n}\n```\n\n## But... autobinding!\n\nIf you need autobinding because a mixin depends on it, you can bind the needed methods in the constructor, or do something like this (haven't given it much thought, suggestions welcome).\n\n```js\nfunction autobind(methodNames){\n    return {\n        componentWillMount: function(){\n            methodNames.forEach((name) => {\n                this[name] = this[name].bind(this);\n            });\n        }\n    };\n}\n\n@reactMixin.decorate(mixin)\n@reactMixin.decorate(autobind(Object.keys(mixin)))\nclass Foo {\n  ...\n}\n```\n\nLike this but want to use it outside of react?  See [smart-mixin][1] and define your own mixin spec.\n\n## Should I use es6 classes?\n\nIt seems to be the future with `createClass` becoming legacy. It's best if everyone uses one pattern for better or worse. `createClass` is being removed from React core in 16.0.0, but you can still install it as a separate package.\n\n[1]: https://github.com/brigand/smart-mixin\n\n","publish_time":1438018608261,"_cnpm_publish_time":1438018608261,"dist-tags":{"beta":"1.4.0-pre1","latest":"5.0.0","pre":"1.3.0-pre"}}