mesosphere-shared-reactjs
Advanced tools
Comparing version 0.0.16 to 0.0.17
{ | ||
"name": "mesosphere-shared-reactjs", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Shared code from mesosphere web projects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,29 +0,52 @@ | ||
function es6ify(mixin) { | ||
if (typeof mixin === "function") { | ||
// mixin is already es6 style | ||
return mixin; | ||
// Babel inherits function | ||
function inherits(subClass, superClass) { | ||
if (typeof superClass !== 'function' && superClass !== null) { | ||
throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); | ||
} | ||
return function (Base) { | ||
// mixin is old-react style plain object | ||
// convert to ES6 class | ||
function MixinClass() {} | ||
MixinClass.prototype = Object.create(Base.prototype); | ||
MixinClass.prototype.constructor = MixinClass; | ||
Object.assign(MixinClass.prototype, mixin); | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return MixinClass; | ||
}; | ||
if (superClass) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(subClass, superClass); | ||
} else { | ||
subClass.__proto__ = superClass; | ||
} | ||
} | ||
} | ||
function mixin() { | ||
var mixins = Array.prototype.slice.call(arguments); | ||
function es6ify(Base, mixin) { | ||
// mixin is old-react style plain object | ||
// convert to ES6 class | ||
function MixinClass() {} | ||
MixinClass.prototype = Object.create(Base.prototype); | ||
MixinClass.prototype.constructor = MixinClass; | ||
Object.assign(MixinClass.prototype, mixin); | ||
return MixinClass; | ||
} | ||
function mixin(Parent /*, ...mixins*/) { | ||
var mixins = Array.prototype.slice.call(arguments, 1); | ||
// Creates base class | ||
function Base() {} | ||
mixins.reverse(); | ||
if (typeof Parent === 'function') { | ||
// Make Base inherit from Parent, if Parent is a class | ||
inherits(Base, Parent); | ||
} else { | ||
// Parent is a regular object, let's add it to mixins | ||
mixins.push(Parent); | ||
} | ||
mixins.forEach(function (mixin) { | ||
Base = es6ify(mixin)(Base); | ||
Base = es6ify(Base, mixin); | ||
}); | ||
@@ -30,0 +53,0 @@ |
54256
1154