Created
May 3, 2018 08:31
-
-
Save championswimmer/0e8eef7775097b7400b8c235c77a4221 to your computer and use it in GitHub Desktop.
fetch_getters.ts
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 Module<S> (module: Function & {state:any}) { | |
const state = new (module.prototype.constructor)({}) | |
if (!module.state) { | |
module.state = <S>{} | |
} | |
const getters = Object.entries(Object.getOwnPropertyDescriptors(module.prototype)) | |
.filter(([key, descriptor]) => typeof descriptor.get === 'function') | |
.forEach(([key,descriptor]) => console.log(descriptor.get.toString()) | |
Object.keys(state).forEach((key: string) => { | |
console.log(state[key]); | |
if (state.hasOwnProperty(key)) { | |
if (typeof state[key] !== 'function') { | |
(module.state as any)[key] = state[key]; | |
} | |
} | |
}) | |
} | |
@Module | |
class Omg { | |
count = 0 | |
get invCount() { | |
return this.count - 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment