Skip to content

Commit

Permalink
fix: it should not throw on dispose call during active disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Jan 17, 2023
1 parent eba7b9a commit 09eb2a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ export function dispose(this: Scope, self = true) {
if (current) {
scopes.push(this);
do {
current._state = STATE_DISPOSED;
if (current._disposal) emptyDisposal(current);
if (current._sources) removeSourceObservers(current, 0);
current[SCOPE] = null;
current._sources = null;
current._observers = null;
current._prevSibling = null;
current._context = null;
current._state = STATE_DISPOSED;
scopes.push(current);
current = current._nextSibling as Computation | null;
if (current && current._prevSibling) current._prevSibling._nextSibling = null;
Expand Down
11 changes: 11 additions & 0 deletions tests/root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type Computation,
type ReadSignal,
type WriteSignal,
onDispose,
} from '../src';

afterEach(() => tick());
Expand Down Expand Up @@ -113,3 +114,13 @@ it('should not observe', () => {
expect(scope._observers).toBeUndefined();
});
});

it('should not throw if dispose called during active disposal process', () => {
root((dispose) => {
onDispose(() => {
dispose();
});

dispose();
});
});

0 comments on commit 09eb2a7

Please sign in to comment.