Skip to content

Commit a8a420c

Browse files
committed
cleanup
1 parent 16f502a commit a8a420c

File tree

12 files changed

+82
-98
lines changed

12 files changed

+82
-98
lines changed

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
set_dev_current_component_function
1414
} from '../../runtime.js';
1515
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
16-
import { queue_after_micro_task } from '../task.js';
16+
import { queue_post_micro_task } from '../task.js';
1717
import { UNINITIALIZED } from '../../../../constants.js';
1818

1919
const PENDING = 0;
@@ -148,7 +148,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
148148
} else {
149149
// Wait a microtask before checking if we should show the pending state as
150150
// the promise might have resolved by the next microtask.
151-
queue_after_micro_task(() => {
151+
queue_post_micro_task(() => {
152152
if (!resolved) update(PENDING, true);
153153
});
154154
}

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import {
2727
set_hydrate_node
2828
} from '../hydration.js';
2929
import { get_next_sibling } from '../operations.js';
30-
import { queue_before_micro_task } from '../task.js';
30+
import { queue_boundary_micro_task } from '../task.js';
3131

32-
const SUSPEND_INCREMENT = Symbol();
33-
const SUSPEND_DECREMENT = Symbol();
32+
const ASYNC_INCREMENT = Symbol();
33+
const ASYNC_DECREMENT = Symbol();
3434

3535
/**
3636
* @param {Effect} boundary
@@ -70,10 +70,10 @@ export function boundary(node, props, boundary_fn) {
7070
/** @type {Effect} */
7171
var boundary_effect;
7272
/** @type {Effect | null} */
73-
var suspended_effect = null;
73+
var async_effect = null;
7474
/** @type {DocumentFragment | null} */
75-
var suspended_fragment = null;
76-
var suspend_count = 0;
75+
var async_fragment = null;
76+
var async_count = 0;
7777

7878
block(() => {
7979
var boundary = /** @type {Effect} */ (active_effect);
@@ -101,35 +101,35 @@ export function boundary(node, props, boundary_fn) {
101101
boundary.fn = (/** @type {unknown} */ input) => {
102102
let pending = props.pending;
103103

104-
if (input === SUSPEND_INCREMENT) {
104+
if (input === ASYNC_INCREMENT) {
105105
if (!pending) {
106106
return false;
107107
}
108108

109-
if (suspend_count++ === 0) {
110-
queue_before_micro_task(() => {
111-
if (suspended_effect) {
109+
if (async_count++ === 0) {
110+
queue_boundary_micro_task(() => {
111+
if (async_effect) {
112112
return;
113113
}
114114

115115
var effect = boundary_effect;
116-
suspended_effect = boundary_effect;
116+
async_effect = boundary_effect;
117117

118118
pause_effect(
119-
suspended_effect,
119+
async_effect,
120120
() => {
121121
/** @type {TemplateNode | null} */
122122
var node = effect.nodes_start;
123123
var end = effect.nodes_end;
124-
suspended_fragment = document.createDocumentFragment();
124+
async_fragment = document.createDocumentFragment();
125125

126126
while (node !== null) {
127127
/** @type {TemplateNode | null} */
128128
var sibling =
129129
node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node));
130130

131131
node.remove();
132-
suspended_fragment.append(node);
132+
async_fragment.append(node);
133133
node = sibling;
134134
}
135135
},
@@ -145,22 +145,22 @@ export function boundary(node, props, boundary_fn) {
145145
return true;
146146
}
147147

148-
if (input === SUSPEND_DECREMENT) {
148+
if (input === ASYNC_DECREMENT) {
149149
if (!pending) {
150150
return false;
151151
}
152152

153-
if (--suspend_count === 0) {
154-
queue_before_micro_task(() => {
155-
if (!suspended_effect) {
153+
if (--async_count === 0) {
154+
queue_boundary_micro_task(() => {
155+
if (!async_effect) {
156156
return;
157157
}
158158
if (boundary_effect) {
159159
destroy_effect(boundary_effect);
160160
}
161-
boundary_effect = suspended_effect;
162-
suspended_effect = null;
163-
anchor.before(/** @type {DocumentFragment} */ (suspended_fragment));
161+
boundary_effect = async_effect;
162+
async_effect = null;
163+
anchor.before(/** @type {DocumentFragment} */ (async_fragment));
164164
resume_effect(boundary_effect);
165165
});
166166
}
@@ -199,7 +199,7 @@ export function boundary(node, props, boundary_fn) {
199199
}
200200

201201
if (failed) {
202-
queue_before_micro_task(() => {
202+
queue_boundary_micro_task(() => {
203203
render_snippet(() => {
204204
failed(
205205
anchor,
@@ -226,9 +226,9 @@ export function boundary(node, props, boundary_fn) {
226226

227227
/**
228228
* @param {Effect | null} effect
229-
* @param {typeof SUSPEND_INCREMENT | typeof SUSPEND_DECREMENT} trigger
229+
* @param {typeof ASYNC_INCREMENT | typeof ASYNC_DECREMENT} trigger
230230
*/
231-
function trigger_suspense(effect, trigger) {
231+
export function trigger_async_boundary(effect, trigger) {
232232
var current = effect;
233233

234234
while (current !== null) {
@@ -241,17 +241,3 @@ function trigger_suspense(effect, trigger) {
241241
current = current.parent;
242242
}
243243
}
244-
245-
export function create_suspense() {
246-
var current = active_effect;
247-
248-
const suspend = () => {
249-
trigger_suspense(current, SUSPEND_INCREMENT);
250-
};
251-
252-
const unsuspend = () => {
253-
trigger_suspense(current, SUSPEND_DECREMENT);
254-
};
255-
256-
return [suspend, unsuspend];
257-
}

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
import { source, mutable_source, internal_set } from '../../reactivity/sources.js';
3535
import { array_from, is_array } from '../../../shared/utils.js';
3636
import { INERT } from '../../constants.js';
37-
import { queue_after_micro_task } from '../task.js';
37+
import { queue_post_micro_task } from '../task.js';
3838
import { active_effect, active_reaction, get } from '../../runtime.js';
3939
import { DEV } from 'esm-env';
4040
import { derived_safe_equal } from '../../reactivity/deriveds.js';
@@ -470,7 +470,7 @@ function reconcile(array, state, anchor, render_fn, flags, is_inert, get_key, ge
470470
}
471471

472472
if (is_animated) {
473-
queue_after_micro_task(() => {
473+
queue_post_micro_task(() => {
474474
if (to_animate === undefined) return;
475475
for (item of to_animate) {
476476
item.a?.apply();

packages/svelte/src/internal/client/dom/css.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { DEV } from 'esm-env';
2-
import { queue_after_micro_task } from './task.js';
2+
import { queue_post_micro_task } from './task.js';
33
import { register_style } from '../dev/css.js';
44

55
/**
66
* @param {Node} anchor
77
* @param {{ hash: string, code: string }} css
88
*/
99
export function append_styles(anchor, css) {
10-
// Use `queue_after_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
11-
queue_after_micro_task(() => {
10+
// Use `queue_post_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
11+
queue_post_micro_task(() => {
1212
var root = anchor.getRootNode();
1313

1414
var target = /** @type {ShadowRoot} */ (root).host

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render_effect, teardown } from '../../../reactivity/effects.js';
33
import { listen_to_event_and_reset_event } from './shared.js';
44
import * as e from '../../../errors.js';
55
import { is } from '../../../proxy.js';
6-
import { queue_after_micro_task } from '../../task.js';
6+
import { queue_post_micro_task } from '../../task.js';
77
import { hydrating } from '../../hydration.js';
88
import { is_runes, untrack } from '../../../runtime.js';
99

@@ -158,14 +158,14 @@ export function bind_group(inputs, group_index, input, get, set = get) {
158158
if (!pending.has(binding_group)) {
159159
pending.add(binding_group);
160160

161-
queue_after_micro_task(() => {
161+
queue_post_micro_task(() => {
162162
// necessary to maintain binding group order in all insertion scenarios
163163
binding_group.sort((a, b) => (a.compareDocumentPosition(b) === 4 ? -1 : 1));
164164
pending.delete(binding_group);
165165
});
166166
}
167167

168-
queue_after_micro_task(() => {
168+
queue_post_micro_task(() => {
169169
if (hydration_mismatch) {
170170
var value;
171171

packages/svelte/src/internal/client/dom/elements/bindings/this.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { STATE_SYMBOL } from '../../../constants.js';
22
import { effect, render_effect } from '../../../reactivity/effects.js';
33
import { untrack } from '../../../runtime.js';
4-
import { queue_after_micro_task } from '../../task.js';
4+
import { queue_post_micro_task } from '../../task.js';
55

66
/**
77
* @param {any} bound_value
@@ -49,7 +49,7 @@ export function bind_this(element_or_component = {}, update, get_value, get_part
4949

5050
return () => {
5151
// We cannot use effects in the teardown phase, we we use a microtask instead.
52-
queue_after_micro_task(() => {
52+
queue_post_micro_task(() => {
5353
if (parts && is_bound_this(get_value(...parts), element_or_component)) {
5454
update(null, ...parts);
5555
}

packages/svelte/src/internal/client/dom/elements/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { teardown } from '../../reactivity/effects.js';
33
import { define_property, is_array } from '../../../shared/utils.js';
44
import { hydrating } from '../hydration.js';
5-
import { queue_after_micro_task } from '../task.js';
5+
import { queue_post_micro_task } from '../task.js';
66
import { FILENAME } from '../../../../constants.js';
77
import * as w from '../../warnings.js';
88
import {
@@ -77,7 +77,7 @@ export function create_event(event_name, dom, handler, options) {
7777
event_name.startsWith('touch') ||
7878
event_name === 'wheel'
7979
) {
80-
queue_after_micro_task(() => {
80+
queue_post_micro_task(() => {
8181
dom.addEventListener(event_name, target_handler, options);
8282
});
8383
} else {

packages/svelte/src/internal/client/dom/elements/misc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { hydrating } from '../hydration.js';
22
import { clear_text_content, get_first_child } from '../operations.js';
3-
import { queue_after_micro_task } from '../task.js';
3+
import { queue_post_micro_task } from '../task.js';
44

55
/**
66
* @param {HTMLElement} dom
@@ -12,7 +12,7 @@ export function autofocus(dom, value) {
1212
const body = document.body;
1313
dom.autofocus = true;
1414

15-
queue_after_micro_task(() => {
15+
queue_post_micro_task(() => {
1616
if (document.activeElement === body) {
1717
dom.focus();
1818
}

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { should_intro } from '../../render.js';
1313
import { current_each_item } from '../blocks/each.js';
1414
import { TRANSITION_GLOBAL, TRANSITION_IN, TRANSITION_OUT } from '../../../../constants.js';
1515
import { BLOCK_EFFECT, EFFECT_RAN, EFFECT_TRANSPARENT } from '../../constants.js';
16-
import { queue_after_micro_task } from '../task.js';
16+
import { queue_post_micro_task } from '../task.js';
1717

1818
/**
1919
* @param {Element} element
@@ -326,7 +326,7 @@ function animate(element, options, counterpart, t2, on_finish) {
326326
var a;
327327
var aborted = false;
328328

329-
queue_after_micro_task(() => {
329+
queue_post_micro_task(() => {
330330
if (aborted) return;
331331
var o = options({ direction: is_intro ? 'in' : 'out' });
332332
a = animate(element, o, counterpart, t2, on_finish);

packages/svelte/src/internal/client/dom/task.js

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,61 @@ let is_micro_task_queued = false;
1010
let is_idle_task_queued = false;
1111

1212
/** @type {Array<() => void>} */
13-
let queued_before_microtasks = [];
13+
let queued_boundary_microtasks = [];
1414
/** @type {Array<() => void>} */
15-
let queued_after_microtasks = [];
15+
let queued_post_microtasks = [];
1616
/** @type {Array<() => void>} */
1717
let queued_idle_tasks = [];
1818

19-
export function flush_before_micro_tasks() {
20-
const tasks = queued_before_microtasks.slice();
21-
queued_before_microtasks = [];
19+
export function flush_boundary_micro_tasks() {
20+
const tasks = queued_boundary_microtasks.slice();
21+
queued_boundary_microtasks = [];
2222
run_all(tasks);
2323
}
2424

25-
function flush_after_micro_tasks() {
26-
const tasks = queued_after_microtasks.slice();
27-
queued_after_microtasks = [];
25+
export function flush_post_micro_tasks() {
26+
const tasks = queued_post_microtasks.slice();
27+
queued_post_microtasks = [];
2828
run_all(tasks);
2929
}
3030

31-
function process_micro_tasks() {
32-
if (is_micro_task_queued) {
33-
is_micro_task_queued = false;
34-
flush_before_micro_tasks();
35-
flush_after_micro_tasks();
31+
export function flush_idle_tasks() {
32+
if (is_idle_task_queued) {
33+
is_idle_task_queued = false;
34+
const tasks = queued_idle_tasks.slice();
35+
queued_idle_tasks = [];
36+
run_all(tasks);
3637
}
3738
}
3839

39-
function process_idle_tasks() {
40-
is_idle_task_queued = false;
41-
const tasks = queued_idle_tasks.slice();
42-
queued_idle_tasks = [];
43-
run_all(tasks);
40+
function flush_all_micro_tasks() {
41+
if (is_micro_task_queued) {
42+
is_micro_task_queued = false;
43+
flush_boundary_micro_tasks();
44+
flush_post_micro_tasks();
45+
}
4446
}
4547

4648
/**
4749
* @param {() => void} fn
4850
*/
49-
export function queue_before_micro_task(fn) {
51+
export function queue_boundary_micro_task(fn) {
5052
if (!is_micro_task_queued) {
5153
is_micro_task_queued = true;
52-
queueMicrotask(process_micro_tasks);
54+
queueMicrotask(flush_all_micro_tasks);
5355
}
54-
queued_before_microtasks.push(fn);
56+
queued_boundary_microtasks.push(fn);
5557
}
5658

5759
/**
5860
* @param {() => void} fn
5961
*/
60-
export function queue_after_micro_task(fn) {
62+
export function queue_post_micro_task(fn) {
6163
if (!is_micro_task_queued) {
6264
is_micro_task_queued = true;
63-
queueMicrotask(process_micro_tasks);
65+
queueMicrotask(flush_all_micro_tasks);
6466
}
65-
queued_after_microtasks.push(fn);
67+
queued_post_microtasks.push(fn);
6668
}
6769

6870
/**
@@ -71,19 +73,7 @@ export function queue_after_micro_task(fn) {
7173
export function queue_idle_task(fn) {
7274
if (!is_idle_task_queued) {
7375
is_idle_task_queued = true;
74-
request_idle_callback(process_idle_tasks);
76+
request_idle_callback(flush_idle_tasks);
7577
}
7678
queued_idle_tasks.push(fn);
7779
}
78-
79-
/**
80-
* Synchronously run any queued tasks.
81-
*/
82-
export function flush_after_tasks() {
83-
if (is_micro_task_queued) {
84-
process_micro_tasks();
85-
}
86-
if (is_idle_task_queued) {
87-
process_idle_tasks();
88-
}
89-
}

0 commit comments

Comments
 (0)