Skip to content

Instantly share code, notes, and snippets.

@reddyonrails
Forked from sebmarkbage/es6mixin.js
Created July 13, 2018 16:46
Show Gist options
  • Save reddyonrails/aa15ed29ed7e1a28deedd72c29556f19 to your computer and use it in GitHub Desktop.
Save reddyonrails/aa15ed29ed7e1a28deedd72c29556f19 to your computer and use it in GitHub Desktop.

Revisions

  1. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions es6mixin.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,8 @@ var Bar2 = base => class extends base {

    class Foo extends mixins(Bar1, Bar2) {
    componentWillMount() {
    console.log('Foo before mixins');
    super.componentWillMount();
    console.log('Foo after mixins');
    }
    }
  2. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 10 additions and 14 deletions.
    24 changes: 10 additions & 14 deletions es6mixin.js
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,15 @@
    var Bar1 = function (base) {
    return class extends base {
    componentWillMount(){
    super.componentWillMount();
    console.log('Bar1');
    }
    };
    var Bar1 = base => class extends base {
    componentWillMount(){
    super.componentWillMount();
    console.log('Bar1');
    }
    };

    var Bar2 = function (base) {
    return class extends base {
    componentWillMount(){
    super.componentWillMount();
    console.log('Bar2');
    }
    };
    var Bar2 = base => class extends base {
    componentWillMount(){
    super.componentWillMount();
    console.log('Bar2');
    }
    };

    class Foo extends mixins(Bar1, Bar2) {
  3. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion mixins.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    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.
    // TODO: Add all possible method names 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);
    }
  4. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions es6mixin.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    var Bar1 = function (base) {
    return class extends base {
    componentWillMount(){
    super();
    super.componentWillMount();
    console.log('Bar1');
    }
    };
    @@ -10,14 +10,14 @@ var Bar1 = function (base) {
    var Bar2 = function (base) {
    return class extends base {
    componentWillMount(){
    super();
    super.componentWillMount();
    console.log('Bar2');
    }
    };
    };

    class Foo extends mixins(Bar1, Bar2) {
    componentWillMount() {
    super();
    super.componentWillMount();
    }
    }
  5. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mixins.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    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);
    }
  6. @sebmarkbage sebmarkbage revised this gist Feb 11, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions mixins.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    function mixins(...mixinFactories) {
    var base = class {};
    for (var i = 0; i < mixinFactories.length; i++) {
    base = mixinFactories[i](base);
    }
    return base;
    }
  7. @sebmarkbage sebmarkbage created this gist Feb 11, 2015.
    23 changes: 23 additions & 0 deletions es6mixin.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    var Bar1 = function (base) {
    return class extends base {
    componentWillMount(){
    super();
    console.log('Bar1');
    }
    };
    };

    var Bar2 = function (base) {
    return class extends base {
    componentWillMount(){
    super();
    console.log('Bar2');
    }
    };
    };

    class Foo extends mixins(Bar1, Bar2) {
    componentWillMount() {
    super();
    }
    }