File tree Expand file tree Collapse file tree 2 files changed +5
-14
lines changed
Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -232,8 +232,6 @@ describe('withViewModel', () => {
232232 children,
233233 model,
234234 } : PropsWithChildren & ViewModelProps < VM1 > ) => {
235- expect ( model . isMounted ) . toBeTruthy ( ) ;
236- expect ( model . spies . mount ) . toBeCalledTimes ( 1 ) ;
237235 return < div data-testid = { `vm-${ model . vm1Value } ` } > { children } </ div > ;
238236 } ) ;
239237
@@ -244,8 +242,6 @@ describe('withViewModel', () => {
244242 children,
245243 model,
246244 } : PropsWithChildren & ViewModelProps < VM2 > ) => {
247- expect ( model . isMounted ) . toBeTruthy ( ) ;
248- expect ( model . spies . mount ) . toBeCalledTimes ( 1 ) ;
249245 return (
250246 < div
251247 data-testid = { `vm-${ model . vm2Value } -${ model . parentViewModel . vm1Value } ` }
@@ -262,8 +258,6 @@ describe('withViewModel', () => {
262258 children,
263259 model,
264260 } : PropsWithChildren & ViewModelProps < VM3 > ) => {
265- expect ( model . isMounted ) . toBeTruthy ( ) ;
266- expect ( model . spies . mount ) . toBeCalledTimes ( 1 ) ;
267261 return (
268262 < div
269263 data-testid = { `vm-${ model . vm3Value } -${ model . parentViewModel . vm2Value } ` }
Original file line number Diff line number Diff line change @@ -137,17 +137,17 @@ export function withViewModel(
137137 new Model ( configCreate ) ;
138138
139139 instances . set ( id , instance ) ;
140+ }
141+
142+ const instance : ViewModel = instances . get ( id ) ! ;
140143
144+ useEffect ( ( ) => {
141145 if ( viewModels ) {
142146 viewModels . attach ( instance ) ;
143147 } else {
144148 instance . mount ( ) ;
145149 }
146- }
147-
148- const instance : ViewModel = instances . get ( id ) ! ;
149150
150- useEffect ( ( ) => {
151151 return ( ) => {
152152 if ( viewModels ) {
153153 viewModels . detach ( id ) ;
@@ -166,10 +166,7 @@ export function withViewModel(
166166
167167 config ?. reactHooks ?.( allProps ) ;
168168
169- if (
170- ( ! viewModels || viewModels . isAbleToRenderView ( id ) ) &&
171- instance . isMounted
172- ) {
169+ if ( ( ! viewModels || viewModels . isAbleToRenderView ( id ) ) && instance ) {
173170 return (
174171 < ActiveViewModelContext . Provider value = { instance } >
175172 < Component { ...( componentProps as any ) } model = { instance } />
You can’t perform that action at this time.
0 commit comments