Skip to content

Commit 2ba92a6

Browse files
committed
fix: revert back withViewModel render modification
1 parent 5c03c30 commit 2ba92a6

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/hoc/with-view-model.test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff 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}`}

src/hoc/with-view-model.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff 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} />

0 commit comments

Comments
 (0)