chore: tidy up (#10870)

* chore: simplify remove()

* deduplicate
pull/10875/head
Rich Harris 2 years ago committed by GitHub
parent a339c28bb7
commit b91392e5bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -90,11 +90,6 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
consequent_fn(anchor);
consequent_dom = block.d;
if (mismatch) {
// Set fragment so that Svelte continues to operate in hydration mode
set_current_hydration_fragment([]);
}
return () => {
// TODO make this unnecessary by linking the dom to the effect,
// and removing automatically on teardown
@ -124,11 +119,6 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
alternate_fn(anchor);
alternate_dom = block.d;
if (mismatch) {
// Set fragment so that Svelte continues to operate in hydration mode
set_current_hydration_fragment([]);
}
return () => {
// TODO make this unnecessary by linking the dom to the effect,
// and removing automatically on teardown
@ -150,6 +140,11 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
});
}
}
if (mismatch) {
// Set fragment so that Svelte continues to operate in hydration mode
set_current_hydration_fragment([]);
}
}, block);
if (elseif) {

@ -50,18 +50,11 @@ export function insert(current, sibling) {
/**
* @param {Array<import('../types.js').TemplateNode> | import('../types.js').TemplateNode} current
* @returns {Element | Comment | Text}
*/
export function remove(current) {
var first_node = current;
if (is_array(current)) {
var i = 0;
var node;
for (; i < current.length; i++) {
node = current[i];
if (i === 0) {
first_node = node;
}
for (var i = 0; i < current.length; i++) {
var node = current[i];
if (node.isConnected) {
node.remove();
}
@ -69,7 +62,6 @@ export function remove(current) {
} else if (current.isConnected) {
current.remove();
}
return /** @type {Element | Comment | Text} */ (first_node);
}
/**

Loading…
Cancel
Save