Last active
December 16, 2018 16:31
-
-
Save kvendrik/0a6acc1bfd6ceb91907091e8011691c8 to your computer and use it in GitHub Desktop.
Decorator example
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 default function showMessage(message: string) { | |
console.log('message', message); | |
return (...args: any[]) => { | |
const [constructorOrComponent, propertyKey, descriptor] = args; | |
if (typeof constructorOrComponent === 'function') { | |
console.log('Class', constructorOrComponent); | |
return constructorOrComponent; | |
} | |
if (!descriptor) { | |
console.log('Prop', constructorOrComponent, propertyKey); | |
return undefined; | |
} | |
console.log('Class method', constructorOrComponent, propertyKey, descriptor); | |
return descriptor; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment