Created
February 17, 2015 19:42
-
-
Save mattmccray/e41e2bf18b13a153ce67 to your computer and use it in GitHub Desktop.
ES6 Classes w/Mixins -- Idea -- React 0.13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function ComponentWithMixins( ...mixins) { | |
class MixedComponent extends React.Component { } | |
for( let mixin of mixins) { | |
// TODO: Would need to handle mixin collisions... | |
for( let name of Object.keys( mixin)) { | |
MixedComponent.prototype[ name]= mixin[ name] | |
} | |
} | |
return MixedComponent | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Can a form of simple mixins be supported via ES6 classes? | |
import {ComponentWithMixins} from './component-with-mixins' | |
let {PureRenderMixin, LinkedStateMixin}= React.addons | |
class MyView extends ComponentWithMixins( PureRenderMixin, LinkedStateMixin) { | |
render() { | |
return ( | |
<div> | |
Hello | |
<input valueLink={ this.linkState( 'name')}/> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting. I'd be curious to see what you come up with.