Created
October 25, 2017 11:55
-
-
Save RobinRadic/d2f36df1306e5b86fc125695c8ae4466 to your computer and use it in GitHub Desktop.
try merging mobx stuff
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 'reflect-metadata' | |
import * as assert from 'assert'; | |
import { action, computed, observable } from 'mobx'; | |
function Mixin<T>(...mixins): new(mixinsParameters?: { [key: string]: any }) => T { | |
// let current = mixins.length - 1; | |
class X { | |
constructor(mixinsParameters?: { [key: string]: any }) { | |
mixinsParameters = mixinsParameters || {}; | |
let mobxers = []; | |
mixins.forEach(mixin => { | |
let params = mixinsParameters[ mixin.name ] === undefined ? [] : mixinsParameters[ mixin.name ] | |
if ( mixin.call !== 'undefined' ) { | |
let pdp = Object.getOwnPropertyDescriptors(mixin.prototype) | |
let inst = mixin.call(this, params) | |
if ( pdp.$mobx ) { | |
let data: any = { $mobx: pdp.$mobx } | |
if ( pdp.__mobxDidRunLazyInitializers ) { | |
data.__mobxDidRunLazyInitializers = pdp.__mobxDidRunLazyInitializers; | |
delete pdp.__mobxDidRunLazyInitializers | |
} | |
if ( pdp.__mobxLazyInitializers ) { | |
data.__mobxLazyInitializers = pdp.__mobxLazyInitializers; | |
delete pdp.__mobxLazyInitializers | |
} | |
if ( pdp.__mobxInitializedProps ) { | |
data.__mobxInitializedProps = pdp.__mobxInitializedProps; | |
delete pdp.__mobxInitializedProps | |
} | |
mobxers.push(data); | |
delete pdp.$mobx; | |
} | |
Object.defineProperties(this, pdp) | |
} | |
}); | |
mobxers.forEach(data => { | |
// merge and assign?!?!~ | |
}) | |
} | |
} | |
mixins.forEach(mixin => { | |
Object.assign(X.prototype, mixin.prototype); | |
}) | |
return <any> X; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment