Last active
December 27, 2015 04:03
-
-
Save license2e/105088798ce7ff9fa7d1 to your computer and use it in GitHub Desktop.
ES6 Mixins
This file contains 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
import Mixin from './utils/mixin'; // see below | |
import Mixin1 from './mixins/mixin1'; | |
class App extends Mixin(React.Component, Mixin1) { // and so on: , Mixin2, Mixin3 | |
componentDidMount() { | |
// this.someFuncFromMixin1() | |
} | |
render () { | |
return ( | |
<div> | |
<h1>Hello world!</h1> | |
</div> | |
) | |
} | |
} |
This file contains 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
// source: https://gist.github.com/badsyntax/b2d9c843236960f145e7 | |
// or another possible way is this way: http://es6-features.org/#ClassInheritanceFromExpressions (but seems more complex) |
This file contains 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 default (Parent, ...mixins) => { | |
class Mixed extends Parent {} | |
Object.assign(Mixed.prototype, ...mixins); | |
return Mixed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment