Comparing version 5.0.0-next.171 to 5.0.0-next.172
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.171", | ||
"version": "5.0.0-next.172", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -9,3 +9,3 @@ import { CLEAN, DERIVED, DESTROYED, DIRTY, MAYBE_DIRTY, UNOWNED } from '../constants.js'; | ||
current_skip_reaction, | ||
execute_reaction_fn, | ||
update_reaction, | ||
destroy_effect_children, | ||
@@ -67,11 +67,12 @@ increment_version | ||
/** | ||
* @param {import('#client').Derived} signal | ||
* @param {import('#client').Derived} derived | ||
* @returns {void} | ||
*/ | ||
function destroy_derived_children(signal) { | ||
destroy_effect_children(signal); | ||
var deriveds = signal.deriveds; | ||
function destroy_derived_children(derived) { | ||
destroy_effect_children(derived); | ||
var deriveds = derived.deriveds; | ||
if (deriveds !== null) { | ||
signal.deriveds = null; | ||
derived.deriveds = null; | ||
for (var i = 0; i < deriveds.length; i += 1) { | ||
@@ -91,3 +92,3 @@ destroy_derived(deriveds[i]); | ||
destroy_derived_children(derived); | ||
var value = execute_reaction_fn(derived); | ||
var value = update_reaction(derived); | ||
updating_derived = previous_updating_derived; | ||
@@ -94,0 +95,0 @@ |
@@ -8,3 +8,3 @@ import { | ||
dev_current_component_function, | ||
execute_effect, | ||
update_effect, | ||
get, | ||
@@ -110,3 +110,3 @@ is_destroying_effect, | ||
set_is_flushing_effect(true); | ||
execute_effect(effect); | ||
update_effect(effect); | ||
effect.f |= EFFECT_RAN; | ||
@@ -272,3 +272,3 @@ } finally { | ||
if (check_dirtiness(effect)) { | ||
execute_effect(effect); | ||
update_effect(effect); | ||
} | ||
@@ -501,3 +501,3 @@ | ||
if (check_dirtiness(effect)) { | ||
execute_effect(effect); | ||
update_effect(effect); | ||
} | ||
@@ -504,0 +504,0 @@ |
@@ -16,3 +16,3 @@ import { DEV } from 'esm-env'; | ||
increment_version, | ||
execute_effect, | ||
update_effect, | ||
inspect_effects | ||
@@ -127,3 +127,3 @@ } from '../runtime.js'; | ||
for (const effect of inspect_effects) { | ||
execute_effect(effect); | ||
update_effect(effect); | ||
} | ||
@@ -130,0 +130,0 @@ |
@@ -183,3 +183,6 @@ import { DEV } from 'esm-env'; | ||
var version = dependency.version; | ||
if ((reaction.f & DIRTY) !== 0) { | ||
// `reaction` might now be dirty, as a result of calling `update_derived` | ||
return true; | ||
} | ||
@@ -191,3 +194,3 @@ if (is_unowned) { | ||
// is also dirty. | ||
if (version > /** @type {import('#client').Derived} */ (reaction).version) { | ||
if (dependency.version > /** @type {import('#client').Derived} */ (reaction).version) { | ||
return true; | ||
@@ -202,5 +205,2 @@ } | ||
} | ||
} else if ((reaction.f & DIRTY) !== 0) { | ||
// `signal` might now be dirty, as a result of calling `check_dirtiness` and/or `update_derived` | ||
return true; | ||
} else if (is_disconnected) { | ||
@@ -210,3 +210,3 @@ // It might be that the derived was was dereferenced from its dependencies but has now come alive again. | ||
// changed since. | ||
if (version > /** @type {import('#client').Derived} */ (reaction).version) { | ||
if (dependency.version > /** @type {import('#client').Derived} */ (reaction).version) { | ||
is_dirty = true; | ||
@@ -299,11 +299,11 @@ } | ||
* @template V | ||
* @param {import('#client').Reaction} signal | ||
* @param {import('#client').Reaction} reaction | ||
* @returns {V} | ||
*/ | ||
export function execute_reaction_fn(signal) { | ||
const previous_dependencies = current_dependencies; | ||
const previous_dependencies_index = current_dependencies_index; | ||
const previous_untracked_writes = current_untracked_writes; | ||
const previous_reaction = current_reaction; | ||
const previous_skip_reaction = current_skip_reaction; | ||
export function update_reaction(reaction) { | ||
var previous_dependencies = current_dependencies; | ||
var previous_dependencies_index = current_dependencies_index; | ||
var previous_untracked_writes = current_untracked_writes; | ||
var previous_reaction = current_reaction; | ||
var previous_skip_reaction = current_skip_reaction; | ||
@@ -313,32 +313,32 @@ current_dependencies = /** @type {null | import('#client').Value[]} */ (null); | ||
current_untracked_writes = null; | ||
current_reaction = (signal.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? signal : null; | ||
current_skip_reaction = !is_flushing_effect && (signal.f & UNOWNED) !== 0; | ||
current_reaction = (reaction.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null; | ||
current_skip_reaction = !is_flushing_effect && (reaction.f & UNOWNED) !== 0; | ||
try { | ||
let res = /** @type {Function} */ (0, signal.fn)(); | ||
let dependencies = /** @type {import('#client').Value<unknown>[]} **/ (signal.deps); | ||
var result = /** @type {Function} */ (0, reaction.fn)(); | ||
var dependencies = /** @type {import('#client').Value<unknown>[]} **/ (reaction.deps); | ||
if (current_dependencies !== null) { | ||
let i; | ||
var dependency; | ||
var i; | ||
if (dependencies !== null) { | ||
const deps_length = dependencies.length; | ||
// Include any dependencies up until the current_dependencies_index. | ||
const full_current_dependencies = | ||
var deps_length = dependencies.length; | ||
/** All dependencies of the reaction, including those tracked on the previous run */ | ||
var array = | ||
current_dependencies_index === 0 | ||
? current_dependencies | ||
: dependencies.slice(0, current_dependencies_index).concat(current_dependencies); | ||
const current_dep_length = full_current_dependencies.length; | ||
// If we have more than 16 elements in the array then use a Set for faster performance | ||
// TODO: evaluate if we should always just use a Set or not here? | ||
const full_current_dependencies_set = | ||
current_dep_length > 16 && deps_length - current_dependencies_index > 1 | ||
? new Set(full_current_dependencies) | ||
: null; | ||
var set = | ||
array.length > 16 && deps_length - current_dependencies_index > 1 ? new Set(array) : null; | ||
for (i = current_dependencies_index; i < deps_length; i++) { | ||
const dependency = dependencies[i]; | ||
if ( | ||
full_current_dependencies_set !== null | ||
? !full_current_dependencies_set.has(dependency) | ||
: !full_current_dependencies.includes(dependency) | ||
) { | ||
remove_reaction(signal, dependency); | ||
dependency = dependencies[i]; | ||
if (set !== null ? !set.has(dependency) : !array.includes(dependency)) { | ||
remove_reaction(reaction, dependency); | ||
} | ||
@@ -354,3 +354,3 @@ } | ||
} else { | ||
signal.deps = /** @type {import('#client').Value<V>[]} **/ ( | ||
reaction.deps = /** @type {import('#client').Value<V>[]} **/ ( | ||
dependencies = current_dependencies | ||
@@ -362,9 +362,12 @@ ); | ||
for (i = current_dependencies_index; i < dependencies.length; i++) { | ||
const dependency = dependencies[i]; | ||
const reactions = dependency.reactions; | ||
dependency = dependencies[i]; | ||
var reactions = dependency.reactions; | ||
if (reactions === null) { | ||
dependency.reactions = [signal]; | ||
} else if (reactions[reactions.length - 1] !== signal && !reactions.includes(signal)) { | ||
reactions.push(signal); | ||
dependency.reactions = [reaction]; | ||
} else if ( | ||
reactions[reactions.length - 1] !== reaction && | ||
!reactions.includes(reaction) | ||
) { | ||
reactions.push(reaction); | ||
} | ||
@@ -374,6 +377,7 @@ } | ||
} else if (dependencies !== null && current_dependencies_index < dependencies.length) { | ||
remove_reactions(signal, current_dependencies_index); | ||
remove_reactions(reaction, current_dependencies_index); | ||
dependencies.length = current_dependencies_index; | ||
} | ||
return res; | ||
return result; | ||
} finally { | ||
@@ -429,12 +433,17 @@ current_dependencies = previous_dependencies; | ||
export function remove_reactions(signal, start_index) { | ||
const dependencies = signal.deps; | ||
if (dependencies !== null) { | ||
const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index); | ||
let i; | ||
for (i = start_index; i < dependencies.length; i++) { | ||
const dependency = dependencies[i]; | ||
// 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_reaction(signal, dependency); | ||
} | ||
var dependencies = signal.deps; | ||
if (dependencies === null) return; | ||
var active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index); | ||
var seen = new Set(); | ||
for (var i = start_index; i < dependencies.length; i++) { | ||
var dependency = dependencies[i]; | ||
if (seen.has(dependency)) continue; | ||
seen.add(dependency); | ||
// 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_reaction(signal, dependency); | ||
} | ||
@@ -446,14 +455,13 @@ } | ||
* @param {import('#client').Reaction} signal | ||
* @param {boolean} [remove_dom] | ||
* @param {boolean} remove_dom | ||
* @returns {void} | ||
*/ | ||
export function destroy_effect_children(signal, remove_dom = true) { | ||
let effect = signal.first; | ||
signal.first = null; | ||
signal.last = null; | ||
var sibling; | ||
export function destroy_effect_children(signal, remove_dom = false) { | ||
var effect = signal.first; | ||
signal.first = signal.last = null; | ||
while (effect !== null) { | ||
sibling = effect.next; | ||
var next = effect.next; | ||
destroy_effect(effect, remove_dom); | ||
effect = sibling; | ||
effect = next; | ||
} | ||
@@ -466,3 +474,3 @@ } | ||
*/ | ||
export function execute_effect(effect) { | ||
export function update_effect(effect) { | ||
var flags = effect.f; | ||
@@ -495,3 +503,3 @@ | ||
execute_effect_teardown(effect); | ||
var teardown = execute_reaction_fn(effect); | ||
var teardown = update_reaction(effect); | ||
effect.teardown = typeof teardown === 'function' ? teardown : null; | ||
@@ -564,3 +572,3 @@ } catch (error) { | ||
if ((effect.f & (DESTROYED | INERT)) === 0 && check_dirtiness(effect)) { | ||
execute_effect(effect); | ||
update_effect(effect); | ||
@@ -570,3 +578,3 @@ // Effects with no dependencies or teardown do not get added to the effect tree. | ||
// don't know if we need to keep them until they are executed. Doing the check | ||
// here (rather than in `execute_effect`) allows us to skip the work for | ||
// here (rather than in `update_effect`) allows us to skip the work for | ||
// immediate effects. | ||
@@ -657,3 +665,3 @@ if (effect.deps === null && effect.first === null && effect.nodes === null) { | ||
if (!is_branch && check_dirtiness(current_effect)) { | ||
execute_effect(current_effect); | ||
update_effect(current_effect); | ||
// Child might have been mutated since running the effect | ||
@@ -793,6 +801,3 @@ child = current_effect.first; | ||
current_dependencies = [signal]; | ||
} else if ( | ||
current_dependencies[current_dependencies.length - 1] !== signal && | ||
!current_dependencies.includes(signal) | ||
) { | ||
} else if (current_dependencies[current_dependencies.length - 1] !== signal) { | ||
current_dependencies.push(signal); | ||
@@ -862,7 +867,7 @@ } | ||
* @param {import('#client').Value} signal | ||
* @param {number} to_status should be DIRTY or MAYBE_DIRTY | ||
* @param {number} status should be DIRTY or MAYBE_DIRTY | ||
* @param {boolean} force_schedule | ||
* @returns {void} | ||
*/ | ||
export function mark_reactions(signal, to_status, force_schedule) { | ||
export function mark_reactions(signal, status, force_schedule) { | ||
var reactions = signal.reactions; | ||
@@ -890,12 +895,7 @@ if (reactions === null) return; | ||
set_signal_status(reaction, to_status); | ||
set_signal_status(reaction, 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) { | ||
// If the signal a) was previously clean or b) is an unowned derived, then mark it | ||
if ((flags & (CLEAN | UNOWNED)) !== 0) { | ||
if ((flags & DERIVED) !== 0) { | ||
mark_reactions( | ||
@@ -902,0 +902,0 @@ /** @type {import('#client').Derived} */ (reaction), |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.171'; | ||
export const VERSION = '5.0.0-next.172'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2115502
46414