Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Created March 13, 2018 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyelMorales/e37875fa47d7084e91218e14ea8e8d00 to your computer and use it in GitHub Desktop.
Save DanyelMorales/e37875fa47d7084e91218e14ea8e8d00 to your computer and use it in GitHub Desktop.
Create getter on the flow
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