Skip to content

Instantly share code, notes, and snippets.

@snaptopixel
Created January 29, 2019 17:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snaptopixel/f81c017f14107e2ef4892ea0e94acbe8 to your computer and use it in GitHub Desktop.
Save snaptopixel/f81c017f14107e2ef4892ea0e94acbe8 to your computer and use it in GitHub Desktop.
Stencil custom decorator example
/*
* @Component()
* class ThemedComponent {
* @Inject() theme: ITheme;
* }
*/
const theme = {foo: 'bar'};
export function Inject() {
return (proto: any, prop: string) => {
const { componentWillLoad } = proto;
proto.componentWillLoad = function() {
this[prop] = theme;
if (componentWillLoad) {
return componentWillLoad.apply(this);
}
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment