Skip to content

Commit

Permalink
#49 Run activate inside componentDidUpdate too when VM is being chang…
Browse files Browse the repository at this point in the history
…ed. (#50)

* #49 Run activate inside componentDidUpdate too when VM is being changed.

* #49 Better naming

Co-authored-by: Michal Kopecký <[email protected]>
  • Loading branch information
kopecmi8 and Michal Kopecký authored Sep 30, 2021
1 parent ed0ec28 commit b395e8b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/views/src/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export default class View extends React.PureComponent<ViewProps, ViewState> {
}

componentDidMount() {
if (this.props.useLifecycle) {
const { vm } = this.props;
if (vm && isActivatable(vm)) {
vm.activate();
}
this.tryActivateViewModel();
}

componentDidUpdate(prevProps: ViewProps) {
if (prevProps.vm !== this.props.vm) {
this.tryActivateViewModel();
}
}

Expand Down Expand Up @@ -68,4 +69,13 @@ export default class View extends React.PureComponent<ViewProps, ViewState> {

return <FoundView vm={vm} />;
}

protected tryActivateViewModel() {
if (this.props.useLifecycle) {
const { vm } = this.props;
if (vm && isActivatable(vm)) {
vm.activate();
}
}
}
}

0 comments on commit b395e8b

Please sign in to comment.