rm-bytes
Ben McCann 2 years ago
parent 87ac2a8f7f
commit 0ed05cfcc0

@ -50,7 +50,7 @@ function no_op() {}
* @returns {void} * @returns {void}
*/ */
function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_fn) { function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_fn) {
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0; const is_controlled = !!(flags & EACH_IS_CONTROLLED);
const block = create_each_block(flags, anchor_node); const block = create_each_block(flags, anchor_node);
/** @type {null | import('./types.js').Render} */ /** @type {null | import('./types.js').Render} */
@ -73,15 +73,13 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
transitions.add(transition); transitions.add(transition);
transition.f(() => { transition.f(() => {
transitions.delete(transition); transitions.delete(transition);
if (transitions.size === 0) { if (!transitions.size && fallback.e) {
if (fallback.e) { if (fallback.d) {
if (fallback.d) { remove(fallback.d);
remove(fallback.d); fallback.d = null;
fallback.d = null;
}
destroy_signal(fallback.e);
fallback.e = null;
} }
destroy_signal(fallback.e);
fallback.e = null;
} }
}); });
}; };
@ -103,7 +101,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
block.d = null; block.d = null;
} }
let anchor = block.a; let anchor = block.a;
const is_controlled = (block.f & EACH_IS_CONTROLLED) !== 0; const is_controlled = !!(block.f & EACH_IS_CONTROLLED);
if (is_controlled) { if (is_controlled) {
anchor = empty(); anchor = empty();
block.a.appendChild(anchor); block.a.appendChild(anchor);
@ -122,7 +120,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
/** @param {import('./types.js').EachBlock} block */ /** @param {import('./types.js').EachBlock} block */
const clear_each = (block) => { const clear_each = (block) => {
const flags = block.f; const flags = block.f;
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0; const is_controlled = !!(flags & EACH_IS_CONTROLLED);
const anchor_node = block.a; const anchor_node = block.a;
reconcile_fn(array, block, anchor_node, is_controlled, render_fn, flags, true, keys); reconcile_fn(array, block, anchor_node, is_controlled, render_fn, flags, true, keys);
}; };
@ -138,21 +136,21 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
: Array.from(maybe_array); : Array.from(maybe_array);
if (key_fn) { if (key_fn) {
keys = array.map(key_fn); keys = array.map(key_fn);
} else if ((flags & EACH_KEYED) === 0) { } else if (!(flags & EACH_KEYED)) {
array.map(no_op); array.map(no_op);
} }
const length = array.length; const length = array.length;
if (fallback_fn) { if (fallback_fn) {
if (length === 0) { if (!length) {
if (block.v.length !== 0 || !render) { if (block.v.length || !render) {
clear_each(block); clear_each(block);
create_fallback_effect(); create_fallback_effect();
return; return;
} }
} else if (block.v.length === 0 && current_fallback) { } else if (!block.v.length && current_fallback) {
const fallback = current_fallback; const fallback = current_fallback;
const transitions = fallback.s; const transitions = fallback.s;
if (transitions.size === 0) { if (!transitions.size) {
if (fallback.d) { if (fallback.d) {
remove(fallback.d); remove(fallback.d);
fallback.d = null; fallback.d = null;
@ -175,7 +173,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
push_destroy_fn(each, () => { push_destroy_fn(each, () => {
const flags = block.f; const flags = block.f;
const anchor_node = block.a; const anchor_node = block.a;
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0; const is_controlled = !!(flags & EACH_IS_CONTROLLED);
let fallback = current_fallback; let fallback = current_fallback;
while (fallback) { while (fallback) {
const dom = fallback.d; const dom = fallback.d;
@ -263,14 +261,14 @@ function reconcile_indexed_array(
var b_blocks; var b_blocks;
var block; var block;
if (active_transitions.length !== 0) { if (active_transitions.length) {
destroy_active_transition_blocks(active_transitions); destroy_active_transition_blocks(active_transitions);
} }
if (b === 0) { if (!b) {
b_blocks = []; b_blocks = [];
// Remove old blocks // Remove old blocks
if (is_controlled && a !== 0) { if (is_controlled && a) {
clear_text_content(dom); clear_text_content(dom);
} }
while (index < length) { while (index < length) {
@ -363,14 +361,14 @@ function reconcile_tracked_array(
var b_blocks; var b_blocks;
var block; var block;
if (active_transitions.length !== 0) { if (active_transitions.length) {
destroy_active_transition_blocks(active_transitions); destroy_active_transition_blocks(active_transitions);
} }
if (b === 0) { if (!b) {
b_blocks = []; b_blocks = [];
// Remove old blocks // Remove old blocks
if (is_controlled && a !== 0) { if (is_controlled && a) {
clear_text_content(dom); clear_text_content(dom);
} }
while (a > 0) { while (a > 0) {
@ -406,7 +404,7 @@ function reconcile_tracked_array(
block = each_item_block(item, key, idx, render_fn, flags); block = each_item_block(item, key, idx, render_fn, flags);
b_blocks[idx] = block; b_blocks[idx] = block;
} }
} else if (a === 0) { } else if (!a) {
// Create new blocks // Create new blocks
while (b > 0) { while (b > 0) {
idx = b_end - --b; idx = b_end - --b;
@ -417,9 +415,8 @@ function reconcile_tracked_array(
insert_each_item_block(block, dom, is_controlled, null); insert_each_item_block(block, dom, is_controlled, null);
} }
} else { } else {
var is_animated = (flags & EACH_IS_ANIMATED) !== 0; var is_animated = !!(flags & EACH_IS_ANIMATED);
var should_update_block = var should_update_block = flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE) || is_animated;
(flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0 || is_animated;
var start = 0; var start = 0;
/** @type {null | Text | Element | Comment} */ /** @type {null | Text | Element | Comment} */
@ -705,16 +702,16 @@ export function get_first_element(block) {
* @returns {void} * @returns {void}
*/ */
function update_each_item_block(block, item, index, type) { function update_each_item_block(block, item, index, type) {
if ((type & EACH_ITEM_REACTIVE) !== 0) { if (type & EACH_ITEM_REACTIVE) {
set_signal_value(block.v, item); set_signal_value(block.v, item);
} else if (is_lazy_property(block.v)) { } else if (is_lazy_property(block.v)) {
block.v.o[block.v.p] = item; block.v.o[block.v.p] = item;
} }
const transitions = block.s; const transitions = block.s;
const index_is_reactive = (type & EACH_INDEX_REACTIVE) !== 0; const index_is_reactive = !!(type & EACH_INDEX_REACTIVE);
// Handle each item animations // Handle each item animations
const each_animation = block.a; const each_animation = block.a;
if (transitions && (type & EACH_KEYED) !== 0 && each_animation) { if (transitions && type & EACH_KEYED && each_animation) {
each_animation(block, transitions, index, index_is_reactive); each_animation(block, transitions, index, index_is_reactive);
} }
if (index_is_reactive) { if (index_is_reactive) {
@ -746,7 +743,7 @@ export function destroy_each_item_block(
transitions.delete(other); transitions.delete(other);
} }
} }
if (transitions.size === 0) { if (!transitions.size) {
block.s = null; block.s = null;
} else { } else {
trigger_transitions(transitions, 'out'); trigger_transitions(transitions, 'out');
@ -775,15 +772,15 @@ export function destroy_each_item_block(
* @returns {import('./types.js').EachItemBlock} * @returns {import('./types.js').EachItemBlock}
*/ */
function each_item_block(item, key, index, render_fn, flags) { function each_item_block(item, key, index, render_fn, flags) {
const each_item_not_reactive = (flags & EACH_ITEM_REACTIVE) === 0; const each_item_not_reactive = !(flags & EACH_ITEM_REACTIVE);
const item_value = each_item_not_reactive const item_value = each_item_not_reactive
? item ? item
: (flags & EACH_IS_IMMUTABLE) === 0 : !(flags & EACH_IS_IMMUTABLE)
? mutable_source(item) ? mutable_source(item)
: source(item); : source(item);
const index_value = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index); const index_value = !(flags & EACH_INDEX_REACTIVE) ? index : source(index);
const block = create_each_item_block(item_value, index_value, key); const block = create_each_item_block(item_value, index_value, key);
const effect = render_effect( const effect = render_effect(

@ -13,7 +13,7 @@ function run_tasks(now) {
task.f(); task.f();
} }
}); });
if (tasks.size !== 0) raf.tick(run_tasks); if (tasks.size) raf.tick(run_tasks);
} }
/** /**
@ -33,7 +33,7 @@ export function clear_loops() {
export function loop(callback) { export function loop(callback) {
/** @type {import('./private.js').TaskEntry} */ /** @type {import('./private.js').TaskEntry} */
let task; let task;
if (tasks.size === 0) raf.tick(run_tasks); if (!tasks.size) raf.tick(run_tasks);
return { return {
promise: new Promise((fulfill) => { promise: new Promise((fulfill) => {
tasks.add((task = { c: callback, f: fulfill })); tasks.add((task = { c: callback, f: fulfill }));

@ -49,7 +49,7 @@ export function remove(current) {
var node; var node;
for (; i < current.length; i++) { for (; i < current.length; i++) {
node = current[i]; node = current[i];
if (i === 0) { if (!i) {
first_node = node; first_node = node;
} }
if (node.isConnected) { if (node.isConnected) {

@ -831,7 +831,7 @@ class ResizeObserverSingleton {
return () => { return () => {
const listeners = this.#listeners.get(element); const listeners = this.#listeners.get(element);
listeners.delete(listener); listeners.delete(listener);
if (listeners.size === 0) { if (!listeners.size) {
this.#listeners.delete(element); this.#listeners.delete(element);
/** @type {ResizeObserver} */ (this.#observer).unobserve(element); /** @type {ResizeObserver} */ (this.#observer).unobserve(element);
} }
@ -1368,23 +1368,23 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
const consequent_transitions = block.c; const consequent_transitions = block.c;
const alternate_transitions = block.a; const alternate_transitions = block.a;
if (result) { if (result) {
if (alternate_transitions === null || alternate_transitions.size === 0) { if (alternate_transitions === null || !alternate_transitions.size) {
execute_effect(alternate_effect); execute_effect(alternate_effect);
} else { } else {
trigger_transitions(alternate_transitions, 'out'); trigger_transitions(alternate_transitions, 'out');
} }
if (consequent_transitions === null || consequent_transitions.size === 0) { if (consequent_transitions === null || !consequent_transitions.size) {
execute_effect(consequent_effect); execute_effect(consequent_effect);
} else { } else {
trigger_transitions(consequent_transitions, 'in'); trigger_transitions(consequent_transitions, 'in');
} }
} else { } else {
if (consequent_transitions === null || consequent_transitions.size === 0) { if (consequent_transitions === null || !consequent_transitions.size) {
execute_effect(consequent_effect); execute_effect(consequent_effect);
} else { } else {
trigger_transitions(consequent_transitions, 'out'); trigger_transitions(consequent_transitions, 'out');
} }
if (alternate_transitions === null || alternate_transitions.size === 0) { if (alternate_transitions === null || !alternate_transitions.size) {
execute_effect(alternate_effect); execute_effect(alternate_effect);
} else { } else {
trigger_transitions(alternate_transitions, 'in'); trigger_transitions(alternate_transitions, 'in');
@ -1643,15 +1643,13 @@ export function component(anchor_node, component_fn, render_fn) {
transitions.add(transition); transitions.add(transition);
transition.f(() => { transition.f(() => {
transitions.delete(transition); transitions.delete(transition);
if (transitions.size === 0) { if (!transitions.size && render.e) {
if (render.e) { if (render.d) {
if (render.d) { remove(render.d);
remove(render.d); render.d = null;
render.d = null;
}
destroy_signal(render.e);
render.e = null;
} }
destroy_signal(render.e);
render.e = null;
} }
}); });
}; };
@ -1690,7 +1688,7 @@ export function component(anchor_node, component_fn, render_fn) {
return; return;
} }
const transitions = render.s; const transitions = render.s;
if (transitions.size === 0) { if (!transitions.size) {
if (render.d) { if (render.d) {
remove(render.d); remove(render.d);
render.d = null; render.d = null;
@ -1769,15 +1767,13 @@ function await_block(anchor_node, input, pending_fn, then_fn, catch_fn) {
transitions.add(transition); transitions.add(transition);
transition.f(() => { transition.f(() => {
transitions.delete(transition); transitions.delete(transition);
if (transitions.size === 0) { if (!transitions.size && render.e) {
if (render.e) { if (render.d) {
if (render.d) { remove(render.d);
remove(render.d); render.d = null;
render.d = null;
}
destroy_signal(render.e);
render.e = null;
} }
destroy_signal(render.e);
render.e = null;
} }
}); });
}; };
@ -1825,7 +1821,7 @@ function await_block(anchor_node, input, pending_fn, then_fn, catch_fn) {
return; return;
} }
const transitions = render.s; const transitions = render.s;
if (transitions.size === 0) { if (!transitions.size) {
if (render.d) { if (render.d) {
remove(render.d); remove(render.d);
render.d = null; render.d = null;
@ -1929,7 +1925,7 @@ export function key(anchor_node, key, render_fn) {
transitions.add(transition); transitions.add(transition);
transition.f(() => { transition.f(() => {
transitions.delete(transition); transitions.delete(transition);
if (transitions.size === 0) { if (!transitions.size) {
if (render.e) { if (render.e) {
if (render.d) { if (render.d) {
remove(render.d); remove(render.d);
@ -1969,7 +1965,7 @@ export function key(anchor_node, key, render_fn) {
return; return;
} }
const transitions = render.s; const transitions = render.s;
if (transitions.size === 0) { if (!transitions.size) {
if (render.d) { if (render.d) {
remove(render.d); remove(render.d);
render.d = null; render.d = null;
@ -2456,7 +2452,7 @@ export function spread_attributes_effect(dom, attrs, lowercase_attributes, css_h
*/ */
export function spread_attributes(dom, prev, attrs, lowercase_attributes, css_hash) { export function spread_attributes(dom, prev, attrs, lowercase_attributes, css_hash) {
const next = object_assign({}, ...attrs); const next = object_assign({}, ...attrs);
const has_hash = css_hash.length !== 0; const has_hash = css_hash.length;
for (const key in prev) { for (const key in prev) {
if (!(key in next)) { if (!(key in next)) {
next[key] = null; next[key] = null;

Loading…
Cancel
Save