Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Last active December 16, 2018 16:31
Show Gist options
  • Save kvendrik/0a6acc1bfd6ceb91907091e8011691c8 to your computer and use it in GitHub Desktop.
Save kvendrik/0a6acc1bfd6ceb91907091e8011691c8 to your computer and use it in GitHub Desktop.
Decorator example
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