Created
June 16, 2018 05:55
-
-
Save okunokentaro/70cdb7f1873ac75285bc70122c23c770 to your computer and use it in GitHub Desktop.
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 { kk } from './emitter'; | |
/** | |
* AoT のために export function での宣言が必須。 | |
*/ | |
/* tslint:disable:only-arrow-functions */ | |
export function KukerComponent() { | |
return cls => { | |
const componentRole = cls.__proto__.name.includes('DecisionMaker') | |
? 'DecisionMaker' | |
: 'Presenter'; | |
const proxyNgOnInit = cls.prototype.ngOnInit; | |
cls.prototype.ngOnInit = function(...args) { | |
// プロキシのため function使用 | |
if (componentRole === 'DecisionMaker') { | |
kk.decisionMakerNgOnInit(cls.name); | |
} else if (componentRole === 'Presenter') { | |
kk.presenterNgOnInit(cls.name); | |
} | |
if (typeof proxyNgOnInit === 'function') { | |
proxyNgOnInit.apply(this, args); | |
} | |
}; | |
const proxyNgOnDestroy = cls.prototype.ngOnDestroy; | |
cls.prototype.ngOnDestroy = function(...args) { | |
// プロキシのため function使用 | |
if (componentRole === 'DecisionMaker') { | |
kk.decisionMakerNgOnDestroy(cls.name); | |
} else if (componentRole === 'Presenter') { | |
kk.presenterNgOnDestroy(cls.name); | |
} | |
if (typeof proxyNgOnDestroy === 'function') { | |
proxyNgOnDestroy.apply(this, args); | |
} | |
}; | |
Object.keys(cls.prototype).forEach(methodName => { | |
if (!methodName.match(/^on/)) { | |
return; | |
} | |
const proxy = cls.prototype[methodName]; | |
cls.prototype[methodName] = function(...args) { | |
// プロキシのため function使用 | |
if (componentRole === 'DecisionMaker') { | |
kk.decisionMakerHandling(cls.name, methodName); | |
} else if (componentRole === 'Presenter') { | |
kk.presenterHandling(cls.name, methodName); | |
} | |
proxy.apply(this, args); | |
}; | |
}); | |
return cls; | |
}; | |
} | |
/* tslint:enable:only-arrow-functions */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment