Created
May 21, 2018 06:25
-
-
Save zbarbuto/63c2801b60395928a63501de9319d946 to your computer and use it in GitHub Desktop.
Basics of the DeveloperFunction decorator
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
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