Skip to content

Commit 137bf82

Browse files
committed
cleanup
1 parent 460ca47 commit 137bf82

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,13 +1454,28 @@ function proxify_object(signal, value, handler, path) {
14541454
return proxy;
14551455
}
14561456

1457+
/**
1458+
* @param {any} value
1459+
*/
1460+
function is_primitive_or_state_object(value) {
1461+
const type = typeof value;
1462+
return (
1463+
value == null ||
1464+
type === 'string' ||
1465+
type === 'number' ||
1466+
type === 'boolean' ||
1467+
type === 'symbol' ||
1468+
type === 'bigint' ||
1469+
STATE_SYMBOL in value
1470+
);
1471+
}
1472+
14571473
/**
14581474
* @template V
14591475
* @param {import("./types.js").ComputationSignal<V>} signal
14601476
* @param {V} derived_value
14611477
* @returns {V}
14621478
*/
1463-
/*#__NO_SIDE_EFFECTS__*/
14641479
function create_derived_proxy(signal, derived_value) {
14651480
const handler = {
14661481
/**
@@ -1484,20 +1499,11 @@ function create_derived_proxy(signal, derived_value) {
14841499
keys.has(prop) &&
14851500
is_last_current_dependency(signal)
14861501
) {
1487-
const type = typeof value;
1502+
// Avoid generating the new_path array until we know it needed to avoid CPU cycles.
14881503
let new_path;
14891504
// We only track paths for primitives or state objects, to avoid tracking objects
14901505
// that likely change all the time.
1491-
if (
1492-
value === void 0 ||
1493-
type === 'string' ||
1494-
type === 'number' ||
1495-
type === 'boolean' ||
1496-
type === 'symbol' ||
1497-
type === 'bigint' ||
1498-
type === null ||
1499-
STATE_SYMBOL in value
1500-
) {
1506+
if (is_primitive_or_state_object(value)) {
15011507
new_path = [...path, prop];
15021508
if (current_derived_proxy_property !== null) {
15031509
capture_fine_grain_derived_property();

0 commit comments

Comments
 (0)