Skip to content

Commit

Permalink
Demonstrate memory leak (#273)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Sitnik <[email protected]>
  • Loading branch information
hypeJunction and ai authored Feb 20, 2024
1 parent 470e362 commit 36178e9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions computed/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,22 @@ test('computed values update first', () => {
$atom.set(2)
deepStrictEqual(values, [1, 2, 'afterAtom', 2, 4, 'afterAtom'])
})

test('cleans up on unmount', () => {
let $source = atom({count: 1})
let $derived = computed($source, (s) => s.count)

equal($derived.lc, 0);
equal($source.lc, 0)

let unbind = $derived.subscribe(() => {
})

equal($derived.lc, 1);
equal($source.lc, 1);

unbind()

equal($derived.lc, 0);
equal($source.lc, 0)
})

0 comments on commit 36178e9

Please sign in to comment.