state-onchange-roots
Rich Harris 5 months ago
parent c2cd807f52
commit df3779dc86

@ -14,19 +14,10 @@ import {
import { PROXY_ONCHANGE_SYMBOL, STATE_SYMBOL } from './constants.js';
import { get_stack } from './dev/tracing.js';
import * as e from './errors.js';
import { batch_onchange, set, source, state } from './reactivity/sources.js';
import { set, source, state } from './reactivity/sources.js';
const array_methods = ['push', 'pop', 'shift', 'unshift', 'splice', 'reverse', 'sort'];
/**
* Used to prevent batching in case we are not setting the length of an array
* @param {any} fn
* @returns
*/
function identity(fn) {
return fn;
}
/**
* @template T
* @param {T} value

@ -27,8 +27,7 @@ import {
UNOWNED,
MAYBE_DIRTY,
BLOCK_EFFECT,
ROOT_EFFECT,
PROXY_ONCHANGE_SYMBOL
ROOT_EFFECT
} from '../constants.js';
import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
@ -47,32 +46,6 @@ export function set_inspect_effects(v) {
inspect_effects = v;
}
/** @type {null | Set<() => void>} */
let onchange_batch = null;
/**
* @param {Function} fn
*/
export function batch_onchange(fn) {
// @ts-expect-error
return function (...args) {
let previous_onchange_batch = onchange_batch;
try {
onchange_batch = new Set();
// @ts-expect-error
return fn.apply(this, args);
} finally {
for (const onchange of /** @type {Set<() => void>} */ (onchange_batch)) {
onchange();
}
onchange_batch = previous_onchange_batch;
}
};
}
/**
* @template V
* @param {V} v

Loading…
Cancel
Save