Created
March 13, 2018 17:22
-
-
Save DanyelMorales/e37875fa47d7084e91218e14ea8e8d00 to your computer and use it in GitHub Desktop.
Create getter on the flow
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
function createMethod(name: string, value: string, parent, theContext) { | |
const getter = function() { | |
parent.endpoint = value; | |
return parent.endpoint; | |
}; | |
Object.defineProperty(theContext, name, { | |
get: getter, | |
enumerable: true, | |
configurable: true | |
}); | |
} | |
function registerMethods(methods: any[], context, parent) { | |
methods.forEach(item => { | |
createMethod(item.k, item.v, parent, context); | |
}); | |
} | |
export default function register(contextMember: string) { | |
return function( | |
target: any, | |
propertyKey: string, | |
descriptor: PropertyDescriptor | |
) { | |
const originalMethod = descriptor.value; | |
descriptor.value = function() { | |
const parent = target[contextMember]; | |
const methods = originalMethod.apply(this, arguments); | |
registerMethods(methods, target, parent); | |
}; | |
return descriptor; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment