Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created February 17, 2015 19:42
Show Gist options
  • Save mattmccray/e41e2bf18b13a153ce67 to your computer and use it in GitHub Desktop.
Save mattmccray/e41e2bf18b13a153ce67 to your computer and use it in GitHub Desktop.

Revisions

  1. mattmccray created this gist Feb 17, 2015.
    13 changes: 13 additions & 0 deletions component-with-mixins.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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
    }
    15 changes: 15 additions & 0 deletions my-view.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // 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>
    )
    }
    }