Socket
Socket
Sign inDemoInstall

svelte

Package Overview
Dependencies
18
Maintainers
3
Versions
617
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0-next.75 to 5.0.0-next.76

src/internal/client/dom/blocks/css-props.js

2

package.json

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "5.0.0-next.75",
"version": "5.0.0-next.76",
"type": "module",

@@ -8,0 +8,0 @@ "types": "./types/index.d.ts",

@@ -1,2 +0,1 @@

export const SOURCE = 1;
export const DERIVED = 1 << 1;

@@ -3,0 +2,0 @@ export const EFFECT = 1 << 2;

import { is_promise } from '../../../common.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { remove } from '../../reconciler.js';
import {
current_block,
destroy_signal,
execute_effect,
flushSync,
push_destroy_fn
} from '../../runtime.js';
import { render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
import { hydrate_block_anchor } from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect, flushSync } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../elements/transitions.js';
import { AWAIT_BLOCK, UNINITIALIZED } from '../../constants.js';

@@ -77,3 +71,3 @@

}
destroy_signal(render.e);
destroy_effect(render.e);
render.e = null;

@@ -185,3 +179,3 @@ }

);
push_destroy_fn(await_effect, () => {
await_effect.ondestroy = () => {
let render = current_render;

@@ -196,8 +190,8 @@ latest_token = {};

if (effect !== null) {
destroy_signal(effect);
destroy_effect(effect);
}
render = render.p;
}
});
};
block.e = await_effect;
}

@@ -16,10 +16,10 @@ import {

set_current_hydration_fragment
} from '../../hydration.js';
import { clear_text_content, empty, map_get, map_set } from '../../operations.js';
import { insert, remove } from '../../reconciler.js';
import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js';
import { render_effect } from '../../reactivity/effects.js';
} from '../hydration.js';
import { clear_text_content, empty } from '../operations.js';
import { insert, remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { source, mutable_source, set } from '../../reactivity/sources.js';
import { trigger_transitions } from '../../transitions.js';
import { is_array, is_frozen } from '../../utils.js';
import { trigger_transitions } from '../elements/transitions.js';
import { is_array, is_frozen, map_get, map_set } from '../../utils.js';
import { EACH_BLOCK, EACH_ITEM_BLOCK, STATE_SYMBOL } from '../../constants.js';

@@ -95,3 +95,3 @@

* @param {null | ((item: V) => string)} key_fn
* @param {(anchor: null, item: V, index: import('../../types.js').MaybeSignal<number>) => void} render_fn
* @param {(anchor: null, item: V, index: import('#client').MaybeSource<number>) => void} render_fn
* @param {null | ((anchor: Node) => void)} fallback_fn

@@ -138,3 +138,3 @@ * @param {typeof reconcile_indexed_array | reconcile_tracked_array} reconcile_fn

}
destroy_signal(fallback.e);
destroy_effect(fallback.e);
fallback.e = null;

@@ -267,3 +267,3 @@ }

push_destroy_fn(each, () => {
each.ondestroy = () => {
const flags = block.f;

@@ -280,3 +280,3 @@ const anchor_node = block.a;

if (effect !== null) {
destroy_signal(effect);
destroy_effect(effect);
}

@@ -287,4 +287,4 @@ fallback = fallback.p;

reconcile_fn([], block, anchor_node, is_controlled, render_fn, flags, false, keys);
destroy_signal(/** @type {import('../../types.js').Effect} */ (render));
});
destroy_effect(/** @type {import('#client').Effect} */ (render));
};

@@ -300,3 +300,3 @@ block.e = each;

* @param {null | ((item: V) => string)} key_fn
* @param {(anchor: null, item: V, index: import('../../types.js').MaybeSignal<number>) => void} render_fn
* @param {(anchor: null, item: V, index: import('#client').MaybeSource<number>) => void} render_fn
* @param {null | ((anchor: Node) => void)} fallback_fn

@@ -314,3 +314,3 @@ * @returns {void}

* @param {number} flags
* @param {(anchor: null, item: V, index: import('../../types.js').MaybeSignal<number>) => void} render_fn
* @param {(anchor: null, item: V, index: import('#client').MaybeSource<number>) => void} render_fn
* @param {null | ((anchor: Node) => void)} fallback_fn

@@ -915,3 +915,3 @@ * @returns {void}

}
destroy_signal(/** @type {import('../../types.js').Effect} */ (block.e));
destroy_effect(/** @type {import('#client').Effect} */ (block.e));
}

@@ -918,0 +918,0 @@

@@ -7,7 +7,7 @@ import { IF_BLOCK } from '../../constants.js';

set_current_hydration_fragment
} from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js';
import { render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
} from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../elements/transitions.js';

@@ -171,3 +171,3 @@ /** @returns {import('../../types.js').IfBlock} */

block.ae = alternate_effect;
push_destroy_fn(if_effect, () => {
if_effect.ondestroy = () => {
if (consequent_dom !== null) {

@@ -179,6 +179,6 @@ remove(consequent_dom);

}
destroy_signal(consequent_effect);
destroy_signal(alternate_effect);
});
destroy_effect(consequent_effect);
destroy_effect(alternate_effect);
};
block.e = if_effect;
}
import { UNINITIALIZED, KEY_BLOCK } from '../../constants.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js';
import { render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../../transitions.js';
import { hydrate_block_anchor } from '../hydration.js';
import { remove } from '../reconciler.js';
import { current_block, execute_effect } from '../../runtime.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { trigger_transitions } from '../elements/transitions.js';
import { safe_not_equal } from '../../reactivity/equality.js';

@@ -61,3 +61,3 @@

}
destroy_signal(render.e);
destroy_effect(render.e);
render.e = null;

@@ -126,3 +126,3 @@ }

mounted = true;
push_destroy_fn(key_effect, () => {
key_effect.ondestroy = () => {
let render = current_render;

@@ -136,8 +136,8 @@ while (render !== null) {

if (effect !== null) {
destroy_signal(effect);
destroy_effect(effect);
}
render = render.p;
}
});
};
block.e = key_effect;
}
import { DEV } from 'esm-env';
import {
get,
updating_derived,
batch_inspect,
current_component_context,
untrack
} from './runtime.js';
import { get, batch_inspect, current_component_context, untrack } from './runtime.js';
import { effect_active } from './reactivity/effects.js';

@@ -23,2 +17,3 @@ import {

import { STATE_SYMBOL, UNINITIALIZED } from './constants.js';
import { updating_derived } from './reactivity/deriveds.js';

@@ -156,4 +151,3 @@ /**

function update_version(signal, d = 1) {
const value = untrack(() => get(signal));
set(signal, value + d);
set(signal, signal.v + d);
}

@@ -160,0 +154,0 @@

import { DEV } from 'esm-env';
import { CLEAN, DERIVED, UNINITIALIZED, UNOWNED } from '../constants.js';
import { current_block, current_consumer, current_effect } from '../runtime.js';
import { push_reference } from './effects.js';
import { default_equals, safe_equal } from './equality.js';
import { CLEAN, DERIVED, DESTROYED, DIRTY, MAYBE_DIRTY, UNOWNED } from '../constants.js';
import {
current_reaction,
current_effect,
destroy_children,
remove_reactions,
set_signal_status,
mark_reactions,
current_skip_reaction,
execute_reaction_fn
} from '../runtime.js';
import { equals, safe_equals } from './equality.js';
export let updating_derived = false;
/**
* @template V
* @param {() => V} fn
* @returns {import('../types.js').Derived<V>}
* @returns {import('#client').Derived<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived(fn) {
let flags = DERIVED | CLEAN;
let flags = DERIVED | DIRTY;
if (current_effect === null) flags |= UNOWNED;

@@ -19,14 +29,11 @@

const signal = {
b: current_block,
c: null,
d: null,
e: default_equals,
reactions: null,
deps: null,
equals,
f: flags,
i: fn,
r: null,
// @ts-expect-error
v: UNINITIALIZED,
w: 0,
x: null,
y: null
fn,
effects: null,
deriveds: null,
v: /** @type {V} */ (null),
version: 0
};

@@ -38,4 +45,8 @@

if (current_consumer !== null) {
push_reference(current_consumer, signal);
if (current_reaction !== null) {
if (current_reaction.deriveds === null) {
current_reaction.deriveds = [signal];
} else {
current_reaction.deriveds.push(signal);
}
}

@@ -54,4 +65,50 @@

const signal = derived(fn);
signal.e = safe_equal;
signal.equals = safe_equals;
return signal;
}
/**
* @param {import('#client').Derived} derived
* @param {boolean} force_schedule
* @returns {void}
*/
export function update_derived(derived, force_schedule) {
var previous_updating_derived = updating_derived;
updating_derived = true;
destroy_children(derived);
var value = execute_reaction_fn(derived);
updating_derived = previous_updating_derived;
var status =
(current_skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null
? MAYBE_DIRTY
: CLEAN;
set_signal_status(derived, status);
if (!derived.equals(value)) {
derived.v = value;
mark_reactions(derived, DIRTY, force_schedule);
if (DEV && force_schedule) {
for (var fn of /** @type {import('#client').DerivedDebug} */ (derived).inspect) fn();
}
}
}
/**
* @param {import('#client').Derived} signal
* @returns {void}
*/
export function destroy_derived(signal) {
destroy_children(signal);
remove_reactions(signal, 0);
set_signal_status(signal, DESTROYED);
signal.effects =
signal.deps =
signal.reactions =
// @ts-expect-error `signal.fn` cannot be `null` while the signal is alive
signal.fn =
null;
}

@@ -6,27 +6,15 @@ import { DEV } from 'esm-env';

current_effect,
destroy_signal,
current_reaction,
destroy_children,
flush_local_render_effects,
get,
is_runes,
remove_reactions,
schedule_effect,
set_signal_status,
untrack
} from '../runtime.js';
import { DIRTY, MANAGED, RENDER_EFFECT, EFFECT, PRE_EFFECT } from '../constants.js';
import { DIRTY, MANAGED, RENDER_EFFECT, EFFECT, PRE_EFFECT, DESTROYED } from '../constants.js';
import { set } from './sources.js';
/**
* @param {import('#client').Reaction} target_signal
* @param {import('#client').Reaction} ref_signal
* @returns {void}
*/
export function push_reference(target_signal, ref_signal) {
const references = target_signal.r;
if (references === null) {
target_signal.r = [ref_signal];
} else {
references.push(ref_signal);
}
}
/**
* @param {import('./types.js').EffectType} type

@@ -36,20 +24,18 @@ * @param {(() => void | (() => void)) | ((b: import('#client').Block) => void | (() => void))} fn

* @param {null | import('#client').Block} block
* @param {boolean} schedule
* @param {boolean} init
* @returns {import('#client').Effect}
*/
function create_effect(type, fn, sync, block, schedule) {
function create_effect(type, fn, sync, block = current_block, init = true) {
/** @type {import('#client').Effect} */
const signal = {
b: block,
c: null,
d: null,
e: null,
block,
deps: null,
f: type | DIRTY,
l: 0,
i: fn,
r: null,
v: null,
w: 0,
x: current_component_context,
y: null
fn,
effects: null,
deriveds: null,
teardown: null,
ctx: current_component_context,
ondestroy: null
};

@@ -59,8 +45,15 @@

signal.l = current_effect.l + 1;
if ((type & MANAGED) === 0) {
push_reference(current_effect, signal);
}
if ((type & MANAGED) === 0) {
if (current_reaction !== null) {
if (current_reaction.effects === null) {
current_reaction.effects = [signal];
} else {
current_reaction.effects.push(signal);
}
}
}
if (schedule) {
if (init) {
schedule_effect(signal, sync);

@@ -93,16 +86,13 @@ }

const apply_component_effect_heuristics =
// Non-nested `$effect(...)` in a component should be deferred
// until the component is mounted
const defer =
current_effect.f & RENDER_EFFECT &&
// TODO do we actually need this? removing them changes nothing
current_component_context !== null &&
!current_component_context.m;
const effect = create_effect(
EFFECT,
fn,
false,
current_block,
!apply_component_effect_heuristics
);
const effect = create_effect(EFFECT, fn, false, current_block, !defer);
if (apply_component_effect_heuristics) {
if (defer) {
const context = /** @type {import('#client').ComponentContext} */ (current_component_context);

@@ -123,3 +113,3 @@ (context.e ??= []).push(effect);

return () => {
destroy_signal(effect);
destroy_effect(effect);
};

@@ -133,3 +123,3 @@ }

export function effect(fn) {
return create_effect(EFFECT, fn, false, current_block, true);
return create_effect(EFFECT, fn, false);
}

@@ -142,3 +132,3 @@

export function managed_effect(fn) {
return create_effect(EFFECT | MANAGED, fn, false, current_block, true);
return create_effect(EFFECT | MANAGED, fn, false);
}

@@ -148,7 +138,6 @@

* @param {() => void | (() => void)} fn
* @param {boolean} sync
* @returns {import('#client').Effect}
*/
export function managed_pre_effect(fn, sync) {
return create_effect(PRE_EFFECT | MANAGED, fn, sync, current_block, true);
export function managed_pre_effect(fn) {
return create_effect(PRE_EFFECT | MANAGED, fn, false);
}

@@ -170,4 +159,5 @@

}
const sync = current_effect !== null && (current_effect.f & RENDER_EFFECT) !== 0;
const runes = is_runes(current_component_context);
return create_effect(

@@ -180,5 +170,3 @@ PRE_EFFECT,

},
sync,
current_block,
true
sync
);

@@ -209,4 +197,2 @@ }

},
true,
current_block,
true

@@ -237,3 +223,3 @@ );

export function invalidate_effect(fn) {
return create_effect(PRE_EFFECT, fn, true, current_block, true);
return create_effect(PRE_EFFECT, fn, true);
}

@@ -254,3 +240,17 @@

}
return create_effect(flags, /** @type {any} */ (fn), sync, block, true);
return create_effect(flags, /** @type {any} */ (fn), sync, block);
}
/**
* @param {import('#client').Effect} signal
* @returns {void}
*/
export function destroy_effect(signal) {
destroy_children(signal);
remove_reactions(signal, 0);
set_signal_status(signal, DESTROYED);
signal.teardown?.();
signal.ondestroy?.();
signal.fn = signal.effects = signal.ondestroy = signal.ctx = signal.block = signal.deps = null;
}

@@ -1,8 +0,4 @@

/**
* @param {unknown} a
* @param {unknown} b
* @returns {boolean}
*/
export function default_equals(a, b) {
return a === b;
/** @type {import('#client').Equals} */
export function equals(value) {
return value === this.v;
}

@@ -23,9 +19,5 @@

/**
* @param {unknown} a
* @param {unknown} b
* @returns {boolean}
*/
export function safe_equal(a, b) {
return !safe_not_equal(a, b);
/** @type {import('#client').Equals} */
export function safe_equals(value) {
return !safe_not_equal(value, this.v);
}

@@ -0,1 +1,14 @@

import { DEV } from 'esm-env';
import {
PROPS_IS_IMMUTABLE,
PROPS_IS_LAZY_INITIAL,
PROPS_IS_RUNES,
PROPS_IS_UPDATED
} from '../../../constants.js';
import { get_descriptor, is_function } from '../utils.js';
import { mutable_source, set } from './sources.js';
import { derived } from './deriveds.js';
import { get, inspect_fn, is_signals_recorded } from '../runtime.js';
import { safe_equals, safe_not_equal } from './equality.js';
/**

@@ -22,1 +35,207 @@ * @param {((value?: number) => number)} fn

}
/**
* The proxy handler for rest props (i.e. `const { x, ...rest } = $props()`).
* Is passed the full `$$props` object and excludes the named props.
* @type {ProxyHandler<{ props: Record<string | symbol, unknown>, exclude: Array<string | symbol> }>}}
*/
const rest_props_handler = {
get(target, key) {
if (target.exclude.includes(key)) return;
return target.props[key];
},
getOwnPropertyDescriptor(target, key) {
if (target.exclude.includes(key)) return;
if (key in target.props) {
return {
enumerable: true,
configurable: true,
value: target.props[key]
};
}
},
has(target, key) {
if (target.exclude.includes(key)) return false;
return key in target.props;
},
ownKeys(target) {
return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
}
};
/**
* @param {Record<string, unknown>} props
* @param {string[]} rest
* @returns {Record<string, unknown>}
*/
export function rest_props(props, rest) {
return new Proxy({ props, exclude: rest }, rest_props_handler);
}
/**
* The proxy handler for spread props. Handles the incoming array of props
* that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps
* them so that the whole thing is passed to the component as the `$$props` argument.
* @template {Record<string | symbol, unknown>} T
* @type {ProxyHandler<{ props: Array<T | (() => T)> }>}}
*/
const spread_props_handler = {
get(target, key) {
let i = target.props.length;
while (i--) {
let p = target.props[i];
if (is_function(p)) p = p();
if (typeof p === 'object' && p !== null && key in p) return p[key];
}
},
getOwnPropertyDescriptor(target, key) {
let i = target.props.length;
while (i--) {
let p = target.props[i];
if (is_function(p)) p = p();
if (typeof p === 'object' && p !== null && key in p) return get_descriptor(p, key);
}
},
has(target, key) {
for (let p of target.props) {
if (is_function(p)) p = p();
if (key in p) return true;
}
return false;
},
ownKeys(target) {
/** @type {Array<string | symbol>} */
const keys = [];
for (let p of target.props) {
if (is_function(p)) p = p();
for (const key in p) {
if (!keys.includes(key)) keys.push(key);
}
}
return keys;
}
};
/**
* @param {Array<Record<string, unknown> | (() => Record<string, unknown>)>} props
* @returns {any}
*/
export function spread_props(...props) {
return new Proxy({ props }, spread_props_handler);
}
/**
* This function is responsible for synchronizing a possibly bound prop with the inner component state.
* It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value.
* @template V
* @param {Record<string, unknown>} props
* @param {string} key
* @param {number} flags
* @param {V | (() => V)} [initial]
* @returns {(() => V | ((arg: V) => V) | ((arg: V, mutation: boolean) => V))}
*/
export function prop(props, key, flags, initial) {
var immutable = (flags & PROPS_IS_IMMUTABLE) !== 0;
var runes = (flags & PROPS_IS_RUNES) !== 0;
var prop_value = /** @type {V} */ (props[key]);
var setter = get_descriptor(props, key)?.set;
if (prop_value === undefined && initial !== undefined) {
if (setter && runes) {
// TODO consolidate all these random runtime errors
throw new Error(
'ERR_SVELTE_BINDING_FALLBACK' +
(DEV
? `: Cannot pass undefined to bind:${key} because the property contains a fallback value. Pass a different value than undefined to ${key}.`
: '')
);
}
// @ts-expect-error would need a cumbersome method overload to type this
if ((flags & PROPS_IS_LAZY_INITIAL) !== 0) initial = initial();
prop_value = /** @type {V} */ (initial);
if (setter) setter(prop_value);
}
var getter = () => {
var value = /** @type {V} */ (props[key]);
if (value !== undefined) initial = undefined;
return value === undefined ? /** @type {V} */ (initial) : value;
};
// easy mode — prop is never written to
if ((flags & PROPS_IS_UPDATED) === 0) {
return getter;
}
// intermediate mode — prop is written to, but the parent component had
// `bind:foo` which means we can just call `$$props.foo = value` directly
if (setter) {
return function (/** @type {V} */ value) {
if (arguments.length === 1) {
/** @type {Function} */ (setter)(value);
return value;
} else {
return getter();
}
};
}
// hard mode. this is where it gets ugly — the value in the child should
// synchronize with the parent, but it should also be possible to temporarily
// set the value to something else locally.
var from_child = false;
var was_from_child = false;
// The derived returns the current value. The underlying mutable
// source is written to from various places to persist this value.
var inner_current_value = mutable_source(prop_value);
var current_value = derived(() => {
var parent_value = getter();
var child_value = get(inner_current_value);
if (from_child) {
from_child = false;
was_from_child = true;
return child_value;
}
was_from_child = false;
return (inner_current_value.v = parent_value);
});
if (!immutable) current_value.equals = safe_equals;
return function (/** @type {V} */ value, mutation = false) {
var current = get(current_value);
// legacy nonsense — need to ensure the source is invalidated when necessary
// also needed for when handling inspect logic so we can inspect the correct source signal
if (is_signals_recorded || (DEV && inspect_fn)) {
// set this so that we don't reset to the parent value if `d`
// is invalidated because of `invalidate_inner_signals` (rather
// than because the parent or child value changed)
from_child = was_from_child;
// invoke getters so that signals are picked up by `invalidate_inner_signals`
getter();
get(inner_current_value);
}
if (arguments.length > 0) {
if (mutation || (immutable ? value !== current : safe_not_equal(value, current))) {
from_child = true;
set(inner_current_value, mutation ? current : value);
get(current_value); // force a synchronisation immediately
}
return value;
}
return current;
};
}
import { DEV } from 'esm-env';
import {
current_component_context,
current_consumer,
current_reaction,
current_dependencies,

@@ -14,3 +14,3 @@ current_effect,

is_runes,
mark_signal_consumers,
mark_reactions,
schedule_effect,

@@ -22,4 +22,4 @@ set_current_untracked_writes,

} from '../runtime.js';
import { default_equals, safe_equal } from './equality.js';
import { CLEAN, DERIVED, DIRTY, MANAGED, SOURCE } from '../constants.js';
import { equals, safe_equals } from './equality.js';
import { CLEAN, DERIVED, DIRTY, MANAGED } from '../constants.js';

@@ -35,11 +35,11 @@ /**

const source = {
c: null,
e: default_equals,
f: SOURCE | CLEAN,
f: 0, // TODO ideally we could skip this altogether, but it causes type errors
reactions: null,
equals: equals,
v: value,
w: 0
version: 0
};
if (DEV) {
/** @type {import('#client').SourceDebug<V>} */ (source).inspect = new Set();
/** @type {import('#client').ValueDebug<V>} */ (source).inspect = new Set();
}

@@ -58,3 +58,3 @@

const s = source(initial_value);
s.e = safe_equal;
s.equals = safe_equals;

@@ -103,5 +103,5 @@ // bind the signal to the component context, in case we need to

!ignore_mutation_validation &&
current_consumer !== null &&
is_runes(null) &&
(current_consumer.f & DERIVED) !== 0
current_reaction !== null &&
is_runes() &&
(current_reaction.f & DERIVED) !== 0
) {

@@ -117,12 +117,12 @@ throw new Error(

}
if (
(signal.f & SOURCE) !== 0 &&
!(/** @type {import('#client').EqualsFunctions} */ (signal.e)(value, signal.v))
) {
if (!signal.equals(value)) {
signal.v = value;
// Increment write version so that unowned signals can properly track dirtyness
signal.w++;
// Increment write version so that unowned signals can properly track dirtiness
signal.version++;
// If the current signal is running for the first time, it won't have any
// consumers as we only allocate and assign the consumers after the signal
// has fully executed. So in the case of ensuring it registers the consumer
// reactions as we only allocate and assign the reactions after the signal
// has fully executed. So in the case of ensuring it registers the reaction
// properly for itself, we need to ensure the current effect actually gets

@@ -136,6 +136,5 @@ // scheduled. i.e:

if (
is_runes(null) &&
is_runes() &&
!ignore_mutation_validation &&
current_effect !== null &&
current_effect.c === null &&
(current_effect.f & CLEAN) !== 0 &&

@@ -155,6 +154,6 @@ (current_effect.f & MANAGED) === 0

}
mark_signal_consumers(signal, DIRTY, true);
// @ts-expect-error
if (DEV && signal.inspect) {
mark_reactions(signal, DIRTY, true);
if (DEV) {
if (is_batching_effect) {

@@ -161,0 +160,0 @@ set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (signal));

@@ -30,7 +30,2 @@ import { subscribe_to_store } from '../../../store/utils.js';

};
// TODO: can we remove this code? it was refactored out when we split up source/comptued signals
// push_destroy_fn(entry.value, () => {
// /** @type {import('#client').StoreReferencesContainer['']} */ (entry).last_value =
// /** @type {import('#client').StoreReferencesContainer['']} */ (entry).value.value;
// });
stores[store_name] = entry;

@@ -114,4 +109,2 @@ }

ref.unsubscribe();
// TODO: can we remove this code? it was refactored out when we split up source/comptued signals
// destroy_signal(ref.value);
}

@@ -134,15 +127,2 @@ });

/**
* @template V
* @param {unknown} val
* @returns {val is import('#client').Store<V>}
*/
export function is_store(val) {
return (
typeof val === 'object' &&
val !== null &&
typeof (/** @type {import('#client').Store<V>} */ (val).subscribe) === 'function'
);
}
/**
* @param {import('#client').Store<number>} store

@@ -149,0 +129,0 @@ * @param {number} store_value

@@ -1,89 +0,61 @@

import type { Block, ComponentContext, EqualsFunctions } from '#client';
import type { DERIVED, EFFECT, PRE_EFFECT, RENDER_EFFECT, SOURCE } from '../constants';
import type { Block, ComponentContext, Equals } from '#client';
import type { EFFECT, PRE_EFFECT, RENDER_EFFECT } from '../constants';
export type SignalFlags =
| typeof SOURCE
| typeof DERIVED
| typeof EFFECT
| typeof PRE_EFFECT
| typeof RENDER_EFFECT;
export type EffectType = typeof EFFECT | typeof PRE_EFFECT | typeof RENDER_EFFECT;
export interface Source<V = unknown> {
/** consumers: Signals that read from the current signal */
c: null | Reaction[];
/** equals: For value equality */
e: null | EqualsFunctions;
/** flags: The types that the signal represent, as a bitwise value */
f: SignalFlags;
/** value: The latest value for this signal */
export interface Signal {
/** Flags bitmask */
f: number;
}
export interface Value<V = unknown> extends Signal {
/** Signals that read from this signal */
reactions: null | Reaction[];
/** Equality function */
equals: Equals;
/** The latest value for this signal */
v: V;
// write version
w: number;
/** Write version */
version: number;
}
export interface SourceDebug<V = unknown> extends Source<V> {
inspect: Set<Function>;
export interface Reaction extends Signal {
/** The reaction function */
fn: null | Function;
/** Signals that this signal reads from */
deps: null | Value[];
/** Effects created inside this signal */
effects: null | Effect[];
/** Deriveds created inside this signal */
deriveds: null | Derived[];
}
export interface Derived<V = unknown> extends Source<V> {
/** dependencies: Signals that this signal reads from */
d: null | Value[];
export interface Derived<V = unknown> extends Value<V>, Reaction {
/** The derived function */
i: () => V;
fn: () => V;
}
// TODO get rid of these
/** references: Anything that a signal owns */
r: null | Reaction[];
/** block: The block associated with this effect/computed */
b: null | Block;
/** context: The associated component if this signal is an effect/computed */
x: null | ComponentContext;
/** destroy: Thing(s) that need destroying */
y: null | (() => void) | Array<() => void>;
export interface Effect extends Reaction {
/** The block associated with this effect */
block: null | Block;
/** The associated component context */
ctx: null | ComponentContext;
/** Stuff to do when the effect is destroyed */
ondestroy: null | (() => void);
/** The effect function */
fn: null | (() => void | (() => void)) | ((b: Block, s: Signal) => void | (() => void));
/** The teardown function returned from the effect function */
teardown: null | (() => void);
/** The depth from the root signal, used for ordering render/pre-effects topologically **/
l: number;
}
export interface DerivedDebug<V = unknown> extends Derived<V> {
export interface ValueDebug<V = unknown> extends Value<V> {
inspect: Set<Function>;
}
export type Effect = {
/** block: The block associated with this effect/computed */
b: null | Block;
/** consumers: Signals that read from the current signal */
c: null | Reaction[];
/** context: The associated component if this signal is an effect/computed */
x: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
d: null | Value[];
/** destroy: Thing(s) that need destroying */
// TODO simplify this, it is only used in one place
y: null | (() => void) | Array<() => void>;
/** equals: For value equality */
e: null | EqualsFunctions;
/** The types that the signal represent, as a bitwise value */
f: SignalFlags;
/** init: The function that we invoke for effects and computeds */
i: null | (() => void | (() => void)) | ((b: Block, s: Signal) => void | (() => void));
/** references: Anything that a signal owns */
r: null | Reaction[];
/** value: The latest value for this signal, doubles as the teardown for effects */
v: null | Function;
/** level: the depth from the root signal, used for ordering render/pre-effects topologically **/
l: number;
/** write version: used for unowned signals to track if their depdendencies are dirty or not **/
w: number;
};
export interface DerivedDebug<V = unknown> extends Derived<V>, ValueDebug<V> {}
export type Reaction = Derived | Effect;
export type Source<V = unknown> = Value<V>;
export type MaybeSignal<T = unknown> = T | Source<T>;
export type UnwrappedSignal<T> = T extends Value<infer U> ? U : T;
export type Value<V = unknown> = Source<V> | Derived<V>;
export type ValueDebug<V = unknown> = SourceDebug<V> | DerivedDebug<V>;
export type Signal = Source | Derived | Effect;
export type MaybeSource<T = unknown> = T | Source<T>;
import { DEV } from 'esm-env';
import { run_all } from '../common.js';
import {

@@ -7,3 +6,2 @@ array_prototype,

get_prototype_of,
is_array,
is_frozen,

@@ -14,3 +12,3 @@ object_freeze,

import { unstate } from './proxy.js';
import { pre_effect } from './reactivity/effects.js';
import { destroy_effect, pre_effect } from './reactivity/effects.js';
import {

@@ -23,3 +21,2 @@ EACH_BLOCK,

DIRTY,
UNINITIALIZED,
MAYBE_DIRTY,

@@ -37,5 +34,4 @@ CLEAN,

import { mutate, set, source } from './reactivity/sources.js';
import { destroy_derived, update_derived } from './reactivity/deriveds.js';
const IS_EFFECT = EFFECT | PRE_EFFECT | RENDER_EFFECT;
const FLUSH_MICROTASK = 0;

@@ -62,6 +58,6 @@ const FLUSH_SYNC = 1;

let flush_count = 0;
// Handle signal reactivity tree dependencies and consumer
// Handle signal reactivity tree dependencies and reactions
/** @type {null | import('./types.js').Reaction} */
export let current_consumer = null;
export let current_reaction = null;

@@ -104,4 +100,4 @@ /** @type {null | import('./types.js').Effect} */

// If we are working with a get() chain that has no active container,
// to prevent memory leaks, we skip adding the consumer.
let current_skip_consumer = false;
// to prevent memory leaks, we skip adding the reaction.
export let current_skip_reaction = false;
// Handle collecting all signals which are read during a specific time frame

@@ -125,11 +121,5 @@ export let is_signals_recorded = false;

export let updating_derived = false;
/**
* @param {null | import('./types.js').ComponentContext} context
* @returns {boolean}
*/
export function is_runes(context) {
const component_context = context || current_component_context;
return component_context !== null && component_context.r;
/** @returns {boolean} */
export function is_runes() {
return current_component_context !== null && current_component_context.r;
}

@@ -170,42 +160,41 @@

/**
* @param {import('./types.js').Signal} signal
* Determines whether a derived or effect is dirty.
* If it is MAYBE_DIRTY, will set the status to CLEAN
* @param {import('./types.js').Reaction} reaction
* @returns {boolean}
*/
function is_signal_dirty(signal) {
const flags = signal.f;
if ((flags & DIRTY) !== 0 || signal.v === UNINITIALIZED) {
function check_dirtiness(reaction) {
var flags = reaction.f;
if ((flags & DIRTY) !== 0) {
return true;
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('./types.js').Reaction} **/ (signal).d;
var dependencies = reaction.deps;
if (dependencies !== null) {
const length = dependencies.length;
let i;
for (i = 0; i < length; i++) {
const dependency = dependencies[i];
if ((dependency.f & MAYBE_DIRTY) !== 0 && !is_signal_dirty(dependency)) {
set_signal_status(dependency, CLEAN);
continue;
}
// The flags can be marked as dirty from the above is_signal_dirty call.
if ((dependency.f & DIRTY) !== 0) {
if ((dependency.f & DERIVED) !== 0) {
update_derived(/** @type {import('./types.js').Derived} **/ (dependency), true);
// Might have been mutated from above get.
if ((signal.f & DIRTY) !== 0) {
return true;
}
} else {
var length = dependencies.length;
for (var i = 0; i < length; i++) {
var dependency = dependencies[i];
if (check_dirtiness(/** @type {import('#client').Derived} */ (dependency))) {
update_derived(/** @type {import('#client').Derived} **/ (dependency), true);
// `signal` might now be dirty, as a result of calling `update_derived`
if ((reaction.f & DIRTY) !== 0) {
return true;
}
}
// If we're workig with an unowned derived signal, then we need to check
// if our dependency write version is higher. If is is then we can assume
// If we're working with an unowned derived signal, then we need to check
// if our dependency write version is higher. If it is then we can assume
// that state has changed to a newer version and thus this unowned signal
// is also dirty.
const is_unowned = (flags & UNOWNED) !== 0;
const write_version = signal.w;
const dep_write_version = dependency.w;
if (is_unowned && dep_write_version > write_version) {
signal.w = dep_write_version;
var is_unowned = (flags & UNOWNED) !== 0;
var version = dependency.version;
if (is_unowned && version > /** @type {import('#client').Derived} */ (reaction).version) {
/** @type {import('#client').Derived} */ (reaction).version = version;
return true;

@@ -215,3 +204,6 @@ }

}
set_signal_status(reaction, CLEAN);
}
return false;

@@ -225,21 +217,19 @@ }

*/
function execute_signal_fn(signal) {
const init = signal.i;
export function execute_reaction_fn(signal) {
const fn = signal.fn;
const flags = signal.f;
const is_render_effect = (flags & RENDER_EFFECT) !== 0;
const previous_dependencies = current_dependencies;
const previous_dependencies_index = current_dependencies_index;
const previous_untracked_writes = current_untracked_writes;
const previous_consumer = current_consumer;
const previous_block = current_block;
const previous_component_context = current_component_context;
const previous_skip_consumer = current_skip_consumer;
const is_render_effect = (flags & RENDER_EFFECT) !== 0;
const previous_reaction = current_reaction;
const previous_skip_reaction = current_skip_reaction;
const previous_untracking = current_untracking;
current_dependencies = /** @type {null | import('./types.js').Value[]} */ (null);
current_dependencies_index = 0;
current_untracked_writes = null;
current_consumer = signal;
current_block = signal.b;
current_component_context = signal.x;
current_skip_consumer = !is_flushing_effect && (flags & UNOWNED) !== 0;
current_reaction = signal;
current_skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
current_untracking = false;

@@ -250,13 +240,14 @@

if (is_render_effect) {
res =
/** @type {(block: import('./types.js').Block, signal: import('./types.js').Signal) => V} */ (
init
)(
/** @type {import('./types.js').Block} */ (signal.b),
/** @type {import('./types.js').Signal} */ (signal)
);
res = /** @type {(block: import('#client').Block, signal: import('#client').Signal) => V} */ (
fn
)(
/** @type {import('#client').Block} */ (
/** @type {import('#client').Effect} */ (signal).block
),
/** @type {import('#client').Signal} */ (signal)
);
} else {
res = /** @type {() => V} */ (init)();
res = /** @type {() => V} */ (fn)();
}
let dependencies = /** @type {import('./types.js').Value<unknown>[]} **/ (signal.d);
let dependencies = /** @type {import('./types.js').Value<unknown>[]} **/ (signal.deps);
if (current_dependencies !== null) {

@@ -285,3 +276,3 @@ let i;

) {
remove_consumer(signal, dependency);
remove_reaction(signal, dependency);
}

@@ -297,3 +288,3 @@ }

} else {
signal.d = /** @type {import('./types.js').Value<V>[]} **/ (
signal.deps = /** @type {import('./types.js').Value<V>[]} **/ (
dependencies = current_dependencies

@@ -303,15 +294,15 @@ );

if (!current_skip_consumer) {
if (!current_skip_reaction) {
for (i = current_dependencies_index; i < dependencies.length; i++) {
const dependency = dependencies[i];
const consumers = dependency.c;
const reactions = dependency.reactions;
if (consumers === null) {
dependency.c = [signal];
} else if (consumers[consumers.length - 1] !== signal) {
if (reactions === null) {
dependency.reactions = [signal];
} else if (reactions[reactions.length - 1] !== signal) {
// TODO: should this be:
//
// } else if (!consumers.includes(signal)) {
// } else if (!reactions.includes(signal)) {
//
consumers.push(signal);
reactions.push(signal);
}

@@ -321,3 +312,3 @@ }

} else if (dependencies !== null && current_dependencies_index < dependencies.length) {
remove_consumers(signal, current_dependencies_index);
remove_reactions(signal, current_dependencies_index);
dependencies.length = current_dependencies_index;

@@ -330,6 +321,4 @@ }

current_untracked_writes = previous_untracked_writes;
current_consumer = previous_consumer;
current_block = previous_block;
current_component_context = previous_component_context;
current_skip_consumer = previous_skip_consumer;
current_reaction = previous_reaction;
current_skip_reaction = previous_skip_reaction;
current_untracking = previous_untracking;

@@ -345,22 +334,22 @@ }

*/
function remove_consumer(signal, dependency) {
const consumers = dependency.c;
let consumers_length = 0;
if (consumers !== null) {
consumers_length = consumers.length - 1;
const index = consumers.indexOf(signal);
function remove_reaction(signal, dependency) {
const reactions = dependency.reactions;
let reactions_length = 0;
if (reactions !== null) {
reactions_length = reactions.length - 1;
const index = reactions.indexOf(signal);
if (index !== -1) {
if (consumers_length === 0) {
dependency.c = null;
if (reactions_length === 0) {
dependency.reactions = null;
} else {
// Swap with last element and then remove.
consumers[index] = consumers[consumers_length];
consumers.pop();
reactions[index] = reactions[reactions_length];
reactions.pop();
}
}
}
if (consumers_length === 0 && (dependency.f & UNOWNED) !== 0) {
if (reactions_length === 0 && (dependency.f & UNOWNED) !== 0) {
// If the signal is unowned then we need to make sure to change it to dirty.
set_signal_status(dependency, DIRTY);
remove_consumers(/** @type {import('./types.js').Reaction} **/ (dependency), 0);
remove_reactions(/** @type {import('./types.js').Derived} **/ (dependency), 0);
}

@@ -374,4 +363,4 @@ }

*/
function remove_consumers(signal, start_index) {
const dependencies = signal.d;
export function remove_reactions(signal, start_index) {
const dependencies = signal.deps;
if (dependencies !== null) {

@@ -382,5 +371,5 @@ const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);

const dependency = dependencies[i];
// Avoid removing a consumer if we know that it is active (start_index will not be 0)
// Avoid removing a reaction if we know that it is active (start_index will not be 0)
if (active_dependencies === null || !active_dependencies.includes(dependency)) {
remove_consumer(signal, dependency);
remove_reaction(signal, dependency);
}

@@ -395,24 +384,15 @@ }

*/
function destroy_references(signal) {
const references = signal.r;
signal.r = null;
if (references !== null) {
let i;
for (i = 0; i < references.length; i++) {
destroy_signal(references[i]);
export function destroy_children(signal) {
if (signal.effects) {
for (var i = 0; i < signal.effects.length; i += 1) {
destroy_effect(signal.effects[i]);
}
signal.effects = null;
}
}
/**
* @param {import('./types.js').Block} block
* @param {unknown} error
* @returns {void}
*/
function report_error(block, error) {
/** @type {import('./types.js').Block | null} */
let current_block = block;
if (current_block !== null) {
throw error;
if (signal.deriveds) {
for (i = 0; i < signal.deriveds.length; i += 1) {
destroy_derived(signal.deriveds[i]);
}
signal.deriveds = null;
}

@@ -429,26 +409,24 @@ }

}
const teardown = signal.v;
const previous_effect = current_effect;
const previous_component_context = current_component_context;
const previous_block = current_block;
const component_context = signal.ctx;
current_effect = signal;
current_component_context = component_context;
current_block = signal.block;
try {
destroy_references(signal);
if (teardown !== null) {
teardown();
}
const possible_teardown = execute_signal_fn(signal);
if (typeof possible_teardown === 'function') {
signal.v = possible_teardown;
}
} catch (error) {
const block = signal.b;
if (block !== null) {
report_error(block, error);
} else {
throw error;
}
destroy_children(signal);
signal.teardown?.();
const teardown = execute_reaction_fn(signal);
signal.teardown = typeof teardown === 'function' ? teardown : null;
} finally {
current_effect = previous_effect;
current_component_context = previous_component_context;
current_block = previous_block;
}
const component_context = signal.x;
if ((signal.f & PRE_EFFECT) !== 0 && current_queued_pre_and_render_effects.length > 0) {

@@ -478,27 +456,25 @@ flush_local_pre_effects(component_context);

function flush_queued_effects(effects) {
const length = effects.length;
if (length > 0) {
infinite_loop_guard();
const previously_flushing_effect = is_flushing_effect;
is_flushing_effect = true;
try {
let i;
for (i = 0; i < length; i++) {
const signal = effects[i];
const flags = signal.f;
if ((flags & (DESTROYED | INERT)) === 0) {
if (is_signal_dirty(signal)) {
set_signal_status(signal, CLEAN);
execute_effect(signal);
} else if ((flags & MAYBE_DIRTY) !== 0) {
set_signal_status(signal, CLEAN);
}
var length = effects.length;
if (length === 0) return;
infinite_loop_guard();
var previously_flushing_effect = is_flushing_effect;
is_flushing_effect = true;
try {
for (var i = 0; i < length; i++) {
var signal = effects[i];
if ((signal.f & (DESTROYED | INERT)) === 0) {
if (check_dirtiness(signal)) {
set_signal_status(signal, CLEAN);
execute_effect(signal);
}
}
} finally {
is_flushing_effect = previously_flushing_effect;
}
} finally {
is_flushing_effect = previously_flushing_effect;
}
effects.length = 0;
}
effects.length = 0;
}

@@ -565,5 +541,6 @@

const target_level = signal.l;
const target_block = signal.b;
const target_block = signal.block;
const is_pre_effect = (flags & PRE_EFFECT) !== 0;
let target_signal;
let target_signal_level;
let is_target_pre_effect;

@@ -573,3 +550,4 @@ let i = length;

target_signal = current_queued_pre_and_render_effects[--i];
if (target_signal.l <= target_level) {
target_signal_level = target_signal.l;
if (target_signal_level <= target_level) {
if (i + 1 === length) {

@@ -579,3 +557,7 @@ should_append = true;

is_target_pre_effect = (target_signal.f & PRE_EFFECT) !== 0;
if (target_signal.b !== target_block || (is_target_pre_effect && !is_pre_effect)) {
if (
target_signal_level < target_level ||
target_signal.block !== target_block ||
(is_target_pre_effect && !is_pre_effect)
) {
i++;

@@ -608,3 +590,3 @@ }

const effect = current_queued_pre_and_render_effects[i];
if ((effect.f & RENDER_EFFECT) !== 0 && effect.x === current_component_context) {
if ((effect.f & RENDER_EFFECT) !== 0 && effect.ctx === current_component_context) {
effects.push(effect);

@@ -626,3 +608,3 @@ current_queued_pre_and_render_effects.splice(i, 1);

const effect = current_queued_pre_and_render_effects[i];
if ((effect.f & PRE_EFFECT) !== 0 && effect.x === context) {
if ((effect.f & PRE_EFFECT) !== 0 && effect.ctx === context) {
effects.push(effect);

@@ -701,30 +683,2 @@ current_queued_pre_and_render_effects.splice(i, 1);

/**
* @param {import('./types.js').Derived} signal
* @param {boolean} force_schedule
* @returns {void}
*/
function update_derived(signal, force_schedule) {
const previous_updating_derived = updating_derived;
updating_derived = true;
destroy_references(signal);
const value = execute_signal_fn(signal);
updating_derived = previous_updating_derived;
const status =
(current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.d !== null
? MAYBE_DIRTY
: CLEAN;
set_signal_status(signal, status);
const equals = /** @type {import('./types.js').EqualsFunctions} */ (signal.e);
if (!equals(value, signal.v)) {
signal.v = value;
mark_signal_consumers(signal, DIRTY, force_schedule);
// @ts-expect-error
if (DEV && signal.inspect && force_schedule) {
for (const fn of /** @type {import('./types.js').ValueDebug} */ (signal).inspect) fn();
}
}
}
/**
* @template V

@@ -751,6 +705,6 @@ * @param {import('./types.js').Value<V>} signal

// Register the dependency on the current consumer signal.
if (current_consumer !== null && (current_consumer.f & MANAGED) === 0 && !current_untracking) {
const unowned = (current_consumer.f & UNOWNED) !== 0;
const dependencies = current_consumer.d;
// Register the dependency on the current reaction signal.
if (current_reaction !== null && (current_reaction.f & MANAGED) === 0 && !current_untracking) {
const unowned = (current_reaction.f & UNOWNED) !== 0;
const dependencies = current_reaction.deps;
if (

@@ -786,3 +740,6 @@ current_dependencies === null &&

if ((flags & DERIVED) !== 0 && is_signal_dirty(signal)) {
if (
(flags & DERIVED) !== 0 &&
check_dirtiness(/** @type {import('#client').Derived} */ (signal))
) {
if (DEV) {

@@ -830,16 +787,13 @@ // we want to avoid tracking indirect dependencies

/**
* @param {import('./types.js').Reaction} signal
* @param {import('#client').Effect} signal
* @param {boolean} inert
* @param {Set<import('./types.js').Block>} [visited_blocks]
* @param {Set<import('#client').Block>} [visited_blocks]
* @returns {void}
*/
function mark_subtree_children_inert(signal, inert, visited_blocks) {
const references = signal.r;
if (references !== null) {
let i;
for (i = 0; i < references.length; i++) {
const reference = references[i];
if ((reference.f & IS_EFFECT) !== 0) {
mark_subtree_inert(reference, inert, visited_blocks);
}
const effects = signal.effects;
if (effects !== null) {
for (var i = 0; i < effects.length; i++) {
const effect = effects[i];
mark_subtree_inert(effect, inert, visited_blocks);
}

@@ -850,5 +804,5 @@ }

/**
* @param {import('./types.js').Reaction} signal
* @param {import('#client').Effect} signal
* @param {boolean} inert
* @param {Set<import('./types.js').Block>} [visited_blocks]
* @param {Set<import('#client').Block>} [visited_blocks]
* @returns {void}

@@ -861,7 +815,7 @@ */

signal.f ^= INERT;
if (!inert && (flags & IS_EFFECT) !== 0 && (flags & CLEAN) === 0) {
schedule_effect(/** @type {import('./types.js').Effect} */ (signal), false);
if (!inert && (flags & CLEAN) === 0) {
schedule_effect(signal, false);
}
// Nested if block effects
const block = signal.b;
const block = signal.block;
if (block !== null && !visited_blocks.has(block)) {

@@ -897,3 +851,3 @@ visited_blocks.add(block);

/**
* @param {import('./types.js').Signal} signal
* @param {import('#client').Value} signal
* @param {number} to_status

@@ -903,56 +857,40 @@ * @param {boolean} force_schedule

*/
export function mark_signal_consumers(signal, to_status, force_schedule) {
const runes = is_runes(null);
const consumers = signal.c;
if (consumers !== null) {
const length = consumers.length;
let i;
for (i = 0; i < length; i++) {
const consumer = consumers[i];
const flags = consumer.f;
const unowned = (flags & UNOWNED) !== 0;
// We skip any effects that are already dirty (but not unowned). Additionally, we also
// skip if the consumer is the same as the current effect (except if we're not in runes or we
// are in force schedule mode).
if ((!force_schedule || !runes) && consumer === current_effect) {
continue;
}
set_signal_status(consumer, to_status);
// If the signal is not clean, then skip over it – with the exception of unowned signals that
// are already maybe dirty. Unowned signals might be dirty because they are not captured as part of an
// effect.
const maybe_dirty = (flags & MAYBE_DIRTY) !== 0;
if ((flags & CLEAN) !== 0 || (maybe_dirty && unowned)) {
if ((consumer.f & IS_EFFECT) !== 0) {
schedule_effect(/** @type {import('./types.js').Effect} */ (consumer), false);
} else {
mark_signal_consumers(consumer, MAYBE_DIRTY, force_schedule);
}
}
export function mark_reactions(signal, to_status, force_schedule) {
var reactions = signal.reactions;
if (reactions === null) return;
var runes = is_runes();
var length = reactions.length;
for (var i = 0; i < length; i++) {
var reaction = reactions[i];
// We skip any effects that are already dirty (but not unowned). Additionally, we also
// skip if the reaction is the same as the current effect (except if we're not in runes or we
// are in force schedule mode).
if ((!force_schedule || !runes) && reaction === current_effect) {
continue;
}
}
}
/**
* @param {import('./types.js').Reaction} signal
* @returns {void}
*/
export function destroy_signal(signal) {
const teardown = /** @type {null | (() => void)} */ (signal.v);
const destroy = signal.y;
const flags = signal.f;
destroy_references(signal);
remove_consumers(signal, 0);
signal.i = signal.r = signal.y = signal.x = signal.b = signal.d = signal.c = null;
set_signal_status(signal, DESTROYED);
if (destroy !== null) {
if (is_array(destroy)) {
run_all(destroy);
} else {
destroy();
var flags = reaction.f;
set_signal_status(reaction, to_status);
// If the signal is not clean, then skip over it – with the exception of unowned signals that
// are already maybe dirty. Unowned signals might be dirty because they are not captured as part of an
// effect.
var maybe_dirty = (flags & MAYBE_DIRTY) !== 0;
var unowned = (flags & UNOWNED) !== 0;
if ((flags & CLEAN) !== 0 || (maybe_dirty && unowned)) {
if ((reaction.f & DERIVED) !== 0) {
mark_reactions(
/** @type {import('#client').Derived} */ (reaction),
MAYBE_DIRTY,
force_schedule
);
} else {
schedule_effect(/** @type {import('#client').Effect} */ (reaction), false);
}
}
}
if (teardown !== null && (flags & IS_EFFECT) !== 0) {
teardown();
}
}

@@ -978,18 +916,2 @@

/**
* @param {import('./types.js').Reaction} signal
* @param {() => void} destroy_fn
* @returns {void}
*/
export function push_destroy_fn(signal, destroy_fn) {
let destroy = signal.y;
if (destroy === null) {
signal.y = destroy_fn;
} else if (is_array(destroy)) {
destroy.push(destroy_fn);
} else {
signal.y = [destroy, destroy_fn];
}
}
const STATUS_MASK = ~(DIRTY | MAYBE_DIRTY | CLEAN);

@@ -1389,4 +1311,4 @@

* @template V
* @param {V} value
* @returns {import('./types.js').UnwrappedSignal<V>}
* @param {V | import('#client').Value<V>} value
* @returns {V}
*/

@@ -1393,0 +1315,0 @@ export function unwrap(value) {

@@ -14,3 +14,3 @@ import {

} from './constants.js';
import type { Reaction, Effect, Signal, Source, Value } from './reactivity/types.js';
import type { Effect, Source, Value } from './reactivity/types.js';

@@ -61,3 +61,3 @@ type EventCallback = (event: Event) => boolean;

export type EqualsFunctions<T = any> = (a: T, v: T) => boolean;
export type Equals = (this: Value, value: unknown) => boolean;

@@ -104,3 +104,3 @@ export type BlockType =

/** effect */
e: null | Reaction;
e: null | Effect;
/** intro */

@@ -156,3 +156,3 @@ i: boolean;

/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */

@@ -170,3 +170,3 @@ p: Block;

/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */

@@ -184,3 +184,3 @@ p: Block;

/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */

@@ -198,3 +198,3 @@ p: Block;

/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */

@@ -220,3 +220,3 @@ p: Block;

/** effewct */
e: null | Reaction;
e: null | Effect;
/** parent */

@@ -261,3 +261,3 @@ p: Block;

/** effect */
e: null | Reaction;
e: null | Effect;
/** transition */

@@ -264,0 +264,0 @@ r: null;

@@ -16,3 +16,41 @@ // Store the references to globals in case someone tries to monkey patch these, causing the below

/** @type {Map<any, any>} */
var map_prototype = Map.prototype;
var map_set_method = map_prototype.set;
var map_get_method = map_prototype.get;
var map_delete_method = map_prototype.delete;
/**
* @template K
* @template V
* @param {Map<K, V>} map
* @param {K} key
* @param {V} value
*/
export function map_set(map, key, value) {
map_set_method.call(map, key, value);
}
/**
* @template K
* @template V
* @param {Map<K, V>} map
* @param {K} key
*/
export function map_delete(map, key) {
map_delete_method.call(map, key);
}
/**
* @template K
* @template V
* @param {Map<K, V>} map
* @param {K} key
* @return {V}
*/
export function map_get(map, key) {
return map_get_method.call(map, key);
}
/**
* @param {any} thing

@@ -19,0 +57,0 @@ * @returns {thing is Function}

@@ -27,3 +27,29 @@ export {

export { key_block as key } from './client/dom/blocks/key.js';
export * from './client/dom/blocks/css-props.js';
export * from './client/dom/blocks/each.js';
export * from './client/dom/blocks/html.js';
export * from './client/dom/blocks/snippet.js';
export * from './client/dom/blocks/svelte-component.js';
export * from './client/dom/blocks/svelte-element.js';
export * from './client/dom/blocks/svelte-head.js';
export * from './client/dom/elements/actions.js';
export * from './client/dom/elements/attributes.js';
export * from './client/dom/elements/class.js';
export * from './client/dom/elements/events.js';
export * from './client/dom/elements/misc.js';
export * from './client/dom/elements/style.js';
export * from './client/dom/elements/transitions.js';
export * from './client/dom/elements/bindings/input.js';
export * from './client/dom/elements/bindings/media.js';
export * from './client/dom/elements/bindings/navigator.js';
export * from './client/dom/elements/bindings/props.js';
export * from './client/dom/elements/bindings/select.js';
export * from './client/dom/elements/bindings/size.js';
export * from './client/dom/elements/bindings/this.js';
export * from './client/dom/elements/bindings/universal.js';
export * from './client/dom/elements/bindings/window.js';
export * from './client/dom/legacy/event-modifiers.js';
export * from './client/dom/legacy/lifecycle.js';
export * from './client/dom/legacy/misc.js';
export * from './client/dom/template.js';
export * from './client/reactivity/deriveds.js';

@@ -39,3 +65,3 @@ export * from './client/reactivity/effects.js';

export { proxy, unstate } from './client/proxy.js';
export { create_custom_element } from './client/custom-element.js';
export { create_custom_element } from './client/dom/elements/custom-element.js';
export {

@@ -47,3 +73,3 @@ child,

$document as document
} from './client/operations.js';
} from './client/dom/operations.js';
export { noop } from './common.js';

@@ -175,3 +175,3 @@ declare module '*.svelte' {

* ```ts
* let { optionalProp = 42, requiredProp } = $props<{ optionalProp?: number; requiredProps: string}>();
* let { optionalProp = 42, requiredProp }: { optionalProp?: number; requiredProps: string } = $props();
* ```

@@ -181,3 +181,3 @@ *

*/
declare function $props<T>(): T;
declare function $props(): any;

@@ -184,0 +184,0 @@ /**

@@ -189,3 +189,3 @@ // This should contain all the public interfaces (not all of them are actually importable, check current Svelte for which ones are).

* ```ts
* let { banner } = $props<{ banner: Snippet<{ text: string }> }>();
* let { banner }: { banner: Snippet<{ text: string }> } = $props();
* ```

@@ -192,0 +192,0 @@ * You can only call a snippet through the `{@render ...}` tag.

@@ -1,103 +0,2 @@

import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
/** @type {Array<keyof Date>} */
const read = [
'getDate',
'getDay',
'getFullYear',
'getHours',
'getMilliseconds',
'getMinutes',
'getMonth',
'getSeconds',
'getTime',
'getTimezoneOffset',
'getUTCDate',
'getUTCDay',
'getUTCFullYear',
'getUTCHours',
'getUTCMilliseconds',
'getUTCMinutes',
'getUTCMonth',
'getUTCSeconds',
// @ts-expect-error this is deprecated
'getYear',
'toDateString',
'toISOString',
'toJSON',
'toLocaleDateString',
'toLocaleString',
'toLocaleTimeString',
'toString',
'toTimeString',
'toUTCString'
];
/** @type {Array<keyof Date>} */
const write = [
'setDate',
'setFullYear',
'setHours',
'setMilliseconds',
'setMinutes',
'setMonth',
'setSeconds',
'setTime',
'setUTCDate',
'setUTCFullYear',
'setUTCHours',
'setUTCMilliseconds',
'setUTCMinutes',
'setUTCMonth',
'setUTCSeconds',
// @ts-expect-error this is deprecated
'setYear'
];
class ReactiveDate extends Date {
#raw_time = source(super.getTime());
static #inited = false;
// We init as part of the first instance so that we can treeshake this class
#init() {
if (!ReactiveDate.#inited) {
ReactiveDate.#inited = true;
const proto = ReactiveDate.prototype;
const date_proto = Date.prototype;
for (const method of read) {
// @ts-ignore
proto[method] = function () {
get(this.#raw_time);
// @ts-ignore
return date_proto[method].call(this);
};
}
for (const method of write) {
// @ts-ignore
proto[method] = function (/** @type {any} */ ...args) {
// @ts-ignore
const v = date_proto[method].apply(this, args);
const time = date_proto.getTime.call(this);
if (time !== this.#raw_time.v) {
set(this.#raw_time, time);
}
return v;
};
}
}
}
/**
* @param {any[]} values
*/
constructor(...values) {
// @ts-ignore
super(...values);
this.#init();
}
}
export { ReactiveDate as Date };
export { ReactiveDate as Date } from './date.js';
export { ReactiveSet as Set } from './set.js';

@@ -9,3 +9,3 @@ // generated during release, do not modify

*/
export const VERSION = '5.0.0-next.75';
export const VERSION = '5.0.0-next.76';
export const PUBLIC_VERSION = '5';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc