Skip to content

Commit 075102f

Browse files
authored
Fix comments
1 parent efc8b72 commit 075102f

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

Diff for: src/react/ScopeProvider.test.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ strictModeSuite(({ wrapper: Outer, isStrict }) => {
262262
} else {
263263
userLifecycle.expectCalledTimesEach(2, 1, 0);
264264
}
265-
// FIXME: This is a jotai strict mode problem. The unmounts are blowing away state
266-
// And both trees have the same value
267265
expect(aValue).toBe(bValue);
268266

269267
act(() => {

Diff for: src/react/useMolecule.test.tsx

+52-3
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,63 @@ strictModeSuite(({ wrapper, isStrict }) => {
148148
expectUserLifecycle(testHook, jeffrey);
149149
});
150150

151-
test.todo("Works with default scope", () => {
151+
test("Works with default scope", () => {
152+
/**
153+
* Default tuples are better memoized, so the default assumptions for number of execution in `expectUserLifecycle` aren't valid
154+
*
155+
* Default tuples can a molecule to only be executed once in strict mode instead of twice.
156+
*
157+
* This is because the tuple itself is a global constant, so it is shared between strict mode renders.
158+
*
159+
* Non-default scope tuples are not global constants, so they are not shared between strict mode renders.
160+
*/
152161
const testHook = () => {
153162
return {
154163
molecule: useMolecule(UseLifecycleMolecule),
155164
};
156165
};
157-
// FIXME: Default tuples are better memoized, so the default assumptions here aren't valid
158-
expectUserLifecycle(testHook, "[email protected]");
166+
const expectedUser = UserScope.defaultValue;
167+
168+
moleculeLifecycle.expectUncalled();
169+
170+
const run1 = renderHook(testHook, {
171+
wrapper,
172+
});
173+
174+
if (isStrict) {
175+
moleculeLifecycle.expectCalledTimesEach(1, 2, 1);
176+
} else {
177+
moleculeLifecycle.expectCalledTimesEach(1, 1, 0);
178+
}
179+
180+
expect(run1.result.current.molecule).toBe(expectedUser);
181+
182+
const run2 = renderHook(testHook, {
183+
wrapper,
184+
});
185+
186+
if (isStrict) {
187+
moleculeLifecycle.expectCalledTimesEach(1, 2, 1);
188+
} else {
189+
moleculeLifecycle.expectCalledTimesEach(1, 1, 0);
190+
}
191+
expect(run2.result.current.molecule).toBe(expectedUser);
192+
193+
run1.unmount();
194+
195+
if (isStrict) {
196+
moleculeLifecycle.expectCalledTimesEach(1, 2, 1);
197+
} else {
198+
moleculeLifecycle.expectCalledTimesEach(1, 1, 0);
199+
}
200+
201+
run2.unmount();
202+
203+
if (isStrict) {
204+
moleculeLifecycle.expectCalledTimesEach(1, 2, 2);
205+
} else {
206+
moleculeLifecycle.expectCalledTimesEach(1, 1, 1);
207+
}
159208
});
160209

161210
function expectUserLifecycle(

Diff for: src/vue/useMolecule.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { onMounted, onUnmounted } from "vue";
1+
import { onUnmounted } from "vue";
22
import type { MoleculeScopeOptions } from "../shared/MoleculeScopeOptions";
33
import type { MoleculeOrInterface } from "../vanilla";
44
import { useInjector } from "./useInjector";
@@ -18,13 +18,10 @@ export const useMolecule = <T>(
1818
const tuples = getTuples(options);
1919
const injector = useInjector();
2020

21-
const [value, handle] = injector.useLazily(mol, ...tuples);
21+
const [, handle] = injector.useLazily(mol, ...tuples);
2222

23-
onMounted(() => {
24-
handle.start();
25-
});
2623
onUnmounted(() => {
2724
handle.stop();
2825
});
29-
return value;
26+
return handle.start();
3027
};

0 commit comments

Comments
 (0)