Last active
November 22, 2016 11:21
-
-
Save kakajika/8e0375ef5e2c728edb16387ac9244f65 to your computer and use it in GitHub Desktop.
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
export function RxAutoDispose<T extends React.ComponentClass<any>>(target: T): T { | |
target.prototype.disposer = new Rx.Subscription() | |
const originalMount = target.prototype.componentDidMount | |
Object.defineProperty(target.prototype, "componentDidMount", { | |
value: function() { | |
console.log("componentDidMount") | |
return originalMount.apply(this, arguments) | |
} | |
}) | |
const originalUnmount = target.prototype.componentWillUnmount | |
Object.defineProperty(target.prototype, "componentWillUnmount", { | |
value: function() { | |
console.log("componentWillUnmount") | |
target.prototype.disposer.unsubscribe() | |
target.prototype.disposer = new Rx.Subscription() | |
return originalUnmount.apply(this, arguments) | |
} | |
}) | |
return target | |
} |
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
@RxAutoDispose | |
export class BookGridCell extends Component<Props, State> { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment