Created
January 29, 2019 17:04
-
-
Save snaptopixel/f81c017f14107e2ef4892ea0e94acbe8 to your computer and use it in GitHub Desktop.
Stencil custom decorator example
This file contains 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
/* | |
* @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