-
-
Save reddyonrails/aa15ed29ed7e1a28deedd72c29556f19 to your computer and use it in GitHub Desktop.
Mixin
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
| var Bar1 = function (base) { | |
| return class extends base { | |
| componentWillMount(){ | |
| super.componentWillMount(); | |
| console.log('Bar1'); | |
| } | |
| }; | |
| }; | |
| var Bar2 = function (base) { | |
| return class extends base { | |
| componentWillMount(){ | |
| super.componentWillMount(); | |
| console.log('Bar2'); | |
| } | |
| }; | |
| }; | |
| class Foo extends mixins(Bar1, Bar2) { | |
| componentWillMount() { | |
| super.componentWillMount(); | |
| } | |
| } |
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
| function mixins(...mixinFactories) { | |
| var base = class {}; | |
| // TODO: Add all possible methods that might call super() to the base class so that they don't throw. | |
| for (var i = 0; i < mixinFactories.length; i++) { | |
| base = mixinFactories[i](base); | |
| } | |
| return base; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment