chore: add derived effect ownership tests (#11538)

* chore: add derived effect ownership tests

* chore: add derived effect ownership tests
pull/11545/head
Dominic Gannaway 8 months ago committed by GitHub
parent f219c795f4
commit 4ea8a5e36b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -121,7 +121,6 @@ export function update_derived(derived, force_schedule) {
*/ */
export function destroy_derived(signal) { export function destroy_derived(signal) {
destroy_derived_children(signal); destroy_derived_children(signal);
destroy_effect_children(signal);
remove_reactions(signal, 0); remove_reactions(signal, 0);
set_signal_status(signal, DESTROYED); set_signal_status(signal, DESTROYED);

@ -8,7 +8,7 @@ import {
user_effect user_effect
} from '../../src/internal/client/reactivity/effects'; } from '../../src/internal/client/reactivity/effects';
import { source, set } from '../../src/internal/client/reactivity/sources'; import { source, set } from '../../src/internal/client/reactivity/sources';
import type { Derived } from '../../src/internal/client/types'; import type { Derived, Value } from '../../src/internal/client/types';
import { proxy } from '../../src/internal/client/proxy'; import { proxy } from '../../src/internal/client/proxy';
import { derived } from '../../src/internal/client/reactivity/deriveds'; import { derived } from '../../src/internal/client/reactivity/deriveds';
@ -376,4 +376,51 @@ describe('signals', () => {
assert.equal(teardown, 1); assert.equal(teardown, 1);
}; };
}); });
test('creating effects within a derived correctly handles ownership', () => {
const log: Array<number | string> = [];
let a: Value<unknown>;
let inner: Value<string | number>;
let outer: Value<string | number>;
const destroy = effect_root(() => {
inner = source(0);
outer = source(0);
render_effect(() => {
a = derived(() => {
log.push('outer', $.get(outer));
effect(() => {
log.push('inner', $.get(inner));
});
});
});
});
return () => {
flushSync(() => {
$.get(a);
});
assert.deepEqual(log, ['outer', 0, 'inner', 0]);
log.length = 0;
flushSync(() => {
set(inner, 1);
$.get(a);
});
assert.deepEqual(log, ['inner', 1]);
log.length = 0;
flushSync(() => {
set(outer, 1);
$.get(a);
});
assert.deepEqual(log, ['outer', 1, 'inner', 1]);
log.length = 0;
flushSync(() => {
set(inner, 2);
$.get(a);
});
assert.deepEqual(log, ['inner', 2]);
destroy();
};
});
}); });

Loading…
Cancel
Save