fix: better update proxy version (#10614)

pull/10616/head
Dominic Gannaway 2 years ago committed by GitHub
parent 2de741219f
commit 533bd9dcda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,12 +2,11 @@ import { DEV } from 'esm-env';
import { import {
get, get,
set, set,
update,
updating_derived, updating_derived,
batch_inspect, batch_inspect,
current_component_context, current_component_context,
set_ignore_mutation_validation, untrack,
untrack set_signal_value
} from './runtime.js'; } from './runtime.js';
import { effect_active } from './reactivity/computations.js'; import { effect_active } from './reactivity/computations.js';
import { import {
@ -150,6 +149,15 @@ export function unstate(value) {
); );
} }
/**
* @param {import('./types.js').Signal<number>} signal
* @param {1 | -1} [d]
*/
function update_version(signal, d = 1) {
const value = untrack(() => get(signal));
set_signal_value(signal, value + d);
}
/** @type {ProxyHandler<import('./types.js').ProxyStateObject<any>>} */ /** @type {ProxyHandler<import('./types.js').ProxyStateObject<any>>} */
const state_proxy_handler = { const state_proxy_handler = {
defineProperty(target, prop, descriptor) { defineProperty(target, prop, descriptor) {
@ -185,9 +193,7 @@ const state_proxy_handler = {
if (s !== undefined) set(s, UNINITIALIZED); if (s !== undefined) set(s, UNINITIALIZED);
if (boolean) { if (boolean) {
set_ignore_mutation_validation(true); update_version(metadata.v);
update(metadata.v);
set_ignore_mutation_validation(false);
} }
return boolean; return boolean;
@ -308,9 +314,7 @@ const state_proxy_handler = {
set(ls, length); set(ls, length);
} }
} }
set_ignore_mutation_validation(true); update_version(metadata.v);
update(metadata.v);
set_ignore_mutation_validation(false);
} }
return true; return true;

@ -1332,7 +1332,7 @@ export function inspect(get_value, inspect = console.log) {
pre_effect(() => { pre_effect(() => {
const fn = () => { const fn = () => {
const value = get_value().map((v) => deep_unstate(v)); const value = untrack(() => get_value().map((v) => deep_unstate(v)));
if (value.length === 2 && typeof value[1] === 'function' && !warned_inspect_changed) { if (value.length === 2 && typeof value[1] === 'function' && !warned_inspect_changed) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn( console.warn(

Loading…
Cancel
Save