chore: improve derived ownership model (#13623)

* chore: improve derived ownership model

* remove redundant assertion
pull/13621/head
Dominic Gannaway 3 weeks ago committed by GitHub
parent 974e823b5b
commit 6a38bbe8a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: improve derived ownership model

@ -31,7 +31,7 @@ import { inspect_effects, set_inspect_effects } from './sources.js';
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived(fn) {
let flags = DERIVED | DIRTY;
var flags = DERIVED | DIRTY;
if (active_effect === null) {
flags |= UNOWNED;
@ -58,9 +58,6 @@ export function derived(fn) {
var derived = /** @type {Derived} */ (active_reaction);
(derived.children ??= []).push(signal);
}
if (active_effect !== null) {
(active_effect.deriveds ??= []).push(signal);
}
return signal;
}

@ -801,10 +801,17 @@ export function get(signal) {
set_signal_status(active_effect, DIRTY);
schedule_effect(active_effect);
}
} else if (is_derived) {
var derived = /** @type {Derived} */ (signal);
var parent = derived.parent;
if (parent !== null && !parent.deriveds?.includes(derived)) {
(parent.deriveds ??= []).push(derived);
}
}
if (is_derived) {
var derived = /** @type {Derived} */ (signal);
derived = /** @type {Derived} */ (signal);
if (check_dirtiness(derived)) {
update_derived(derived);

@ -488,7 +488,6 @@ describe('signals', () => {
assert.equal(a?.deps?.length, 1);
assert.equal(s?.reactions?.length, 1);
destroy();
assert.equal(a?.deps, null);
assert.equal(s?.reactions, null);
};
});

Loading…
Cancel
Save