chore: remove ignore_mutation_validation (#10789)

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10793/head
Rich Harris 11 months ago committed by GitHub
parent 2701c0ad64
commit bd687c6504
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,7 +8,6 @@ import {
current_untracking, current_untracking,
flushSync, flushSync,
get, get,
ignore_mutation_validation,
is_batching_effect, is_batching_effect,
is_runes, is_runes,
mark_reactions, mark_reactions,
@ -19,7 +18,7 @@ import {
untrack untrack
} from '../runtime.js'; } from '../runtime.js';
import { equals, safe_equals } from './equality.js'; import { equals, safe_equals } from './equality.js';
import { CLEAN, DERIVED, DIRTY, MANAGED } from '../constants.js'; import { CLEAN, DERIVED, DIRTY, MANAGED, UNINITIALIZED } from '../constants.js';
/** /**
* @template V * @template V
@ -93,9 +92,11 @@ export function mutate(source, value) {
* @returns {V} * @returns {V}
*/ */
export function set(signal, value) { export function set(signal, value) {
var initialized = signal.v !== UNINITIALIZED;
if ( if (
!current_untracking && !current_untracking &&
!ignore_mutation_validation && initialized &&
current_reaction !== null && current_reaction !== null &&
is_runes() && is_runes() &&
(current_reaction.f & DERIVED) !== 0 (current_reaction.f & DERIVED) !== 0
@ -124,11 +125,10 @@ export function set(signal, value) {
// //
// $effect(() => x++) // $effect(() => x++)
// //
// We additionally want to skip this logic for when ignore_mutation_validation is // We additionally want to skip this logic when initialising store sources
// true, as stores write to source signal on initialisation.
if ( if (
is_runes() && is_runes() &&
!ignore_mutation_validation && initialized &&
current_effect !== null && current_effect !== null &&
(current_effect.f & CLEAN) !== 0 && (current_effect.f & CLEAN) !== 0 &&
(current_effect.f & MANAGED) === 0 (current_effect.f & MANAGED) === 0

@ -1,7 +1,7 @@
import { subscribe_to_store } from '../../../store/utils.js'; import { subscribe_to_store } from '../../../store/utils.js';
import { noop } from '../../common.js'; import { noop } from '../../common.js';
import { UNINITIALIZED } from '../constants.js'; import { UNINITIALIZED } from '../constants.js';
import { get, set_ignore_mutation_validation, untrack } from '../runtime.js'; import { get, untrack } from '../runtime.js';
import { user_effect } from './effects.js'; import { user_effect } from './effects.js';
import { mutable_source, set } from './sources.js'; import { mutable_source, set } from './sources.js';
@ -74,13 +74,7 @@ function connect_store_to_signal(store, source) {
return noop; return noop;
} }
/** @param {V} v */ return subscribe_to_store(store, (v) => set(source, v));
const run = (v) => {
set_ignore_mutation_validation(true);
set(source, v);
set_ignore_mutation_validation(false);
};
return subscribe_to_store(store, run);
} }
/** /**

@ -84,12 +84,6 @@ export function set_last_inspected_signal(signal) {
/** If `true`, `get`ting the signal should not register it as a dependency */ /** If `true`, `get`ting the signal should not register it as a dependency */
export let current_untracking = false; export let current_untracking = false;
/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */
export let ignore_mutation_validation = false;
/** @param {boolean} value */
export function set_ignore_mutation_validation(value) {
ignore_mutation_validation = value;
}
// If we are working with a get() chain that has no active container, // If we are working with a get() chain that has no active container,
// to prevent memory leaks, we skip adding the reaction. // to prevent memory leaks, we skip adding the reaction.

Loading…
Cancel
Save