Skip to content

Instantly share code, notes, and snippets.

@zbarbuto
Created May 21, 2018 06:25
Show Gist options
  • Save zbarbuto/63c2801b60395928a63501de9319d946 to your computer and use it in GitHub Desktop.
Save zbarbuto/63c2801b60395928a63501de9319d946 to your computer and use it in GitHub Desktop.
Basics of the DeveloperFunction decorator
export const DEV_FUN_KEY = `DEVELOPER_FUNCTIONS`;
export function DeveloperFunction(opts: any) {
return function(target: any, key: string) {
const metaTarget = target.constructor;
const developerFunctions = getOwnMetadata(DEV_FUN_KEY, metaTarget) || [];
if (Array.isArray(opts)) {
opts.forEach(opt => {
developerFunctions.push({
key,
...opt
});
});
} else {
developerFunctions.push({ key, ...opts });
}
defineMetadata(DEV_FUN_KEY, developerFunctions, metaTarget);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment