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
| function observable(target: any, propertyKey: string): PropertyDecorator { | |
| return { | |
| get(): any { | |
| return this._value; | |
| }, | |
| set(value: any) { | |
| console.log(`Gotcha! value is ${value}.`); | |
| this._value = value; | |
| }, | |
| }; |
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
| function observable(target, propertyKey) { | |
| console.log(`decorate ${propertyKey}`); | |
| return { | |
| get() {}, | |
| set() {}, | |
| }; | |
| } | |
| class State { |
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
| function observable(target: any, propertyKey: string): PropertyDecorator { | |
| console.log(`decorate ${propertyKey}`); | |
| // This is property descriptor | |
| return { | |
| get() {}, | |
| set() {}, | |
| }; | |
| } |
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
| function observable(target, propertyKey) { | |
| console.log(`decorate ${propertyKey}`); | |
| } | |
| class State { | |
| } | |
| observable(State.prototype, "foo"); |
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
| function observable(target: any, propertyKey: string) { | |
| console.log(`decorate ${propertyKey}`); | |
| } | |
| class State { | |
| @observable foo; | |
| } |
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
| StyledComponent.componentId = componentId; | |
| StyledComponent.target = TargetComponent; |
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
| const myStyled = (TargetComponent) => (strs, ...exprs) => class extends React.Component { | |
| interpolateStyle() { | |
| const style = exprs.reduce((result, expr, index) => { | |
| const isFunc = typeof expr === 'function'; | |
| const value = isFunc ? expr(this.props) : expr; | |
| return result + value + strs[index + 1]; | |
| }, strs[0]); | |
| this.element.setAttribute('style', style); |
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
| const myStyled = (TargetComponent) => ([style]) => class extends React.Component { | |
| componentDidMount() { | |
| this.element.setAttribute('style', style); | |
| } | |
| render() { | |
| return ( | |
| <TargetComponent {...this.props} ref={element => this.element = element } /> | |
| ); | |
| } |
NewerOlder