-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
155 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import LeakDetector from 'jest-leak-detector' | ||
import { expect, it } from 'vitest' | ||
import { state, State, Computed, computed, createStore } from '..' | ||
|
||
|
||
it('should release memory after delete state', async () => { | ||
const store = createStore() | ||
let base: State<object> | undefined = state({}) | ||
|
||
const detector = new LeakDetector(store.get(base)) | ||
base = undefined | ||
|
||
expect(await detector.isLeaking()).toBe(false) | ||
}) | ||
|
||
it('should release memory after base state & derived computed is deleted', async () => { | ||
const store = createStore() | ||
let base: State<object> | undefined = state({}) | ||
let derived: Computed<object> | undefined = computed((get) => ({ | ||
obj: base && get(base), | ||
})) | ||
const detector1 = new LeakDetector(store.get(base)) | ||
const detector2 = new LeakDetector(store.get(derived)) | ||
|
||
base = undefined | ||
derived = undefined | ||
|
||
expect(await detector1.isLeaking()).toBe(false) | ||
expect(await detector2.isLeaking()).toBe(false) | ||
}) | ||
|
||
it('with a long-lived base state', async () => { | ||
const store = createStore() | ||
const objAtom = state({}) | ||
|
||
let cmpt: Computed<object> | undefined = computed((get) => ({ | ||
obj: get(objAtom), | ||
})) | ||
|
||
const detector = new LeakDetector(store.get(cmpt)) | ||
cmpt = undefined | ||
expect(await detector.isLeaking()).toBe(false) | ||
}) | ||
|
||
it.skip('should not hold onto dependent atoms that are not mounted', async () => { | ||
const store = createStore() | ||
const objAtom = state({}) | ||
let depAtom: Computed<unknown> | undefined = computed((get) => get(objAtom)) | ||
const detector = new LeakDetector(depAtom) | ||
store.get(depAtom) | ||
depAtom = undefined | ||
await expect(detector.isLeaking()).resolves.toBe(false) | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { atom, compute, action, createStore } from './rippling' | ||
export type { Atom, Compute, Action, Store } from './typing' | ||
export { state, computed, effect, createStore } from './rippling' | ||
export type { State, Computed, Effect, Store } from './typing' |
Oops, something went wrong.