Skip to content

Commit 29890bb

Browse files
chore: move signal logic into subdirectory (#10582)
* move effect code * move source code * derived * move more stuff * simplify * init is a daft name for something that runs repeatedly * remove unneeded effect variant * chore: reshuffle part2 (#10588) * extract store * move prop/init to render * introduce constants file and move all constants there to reduce cyclic dependencies * move reactive_import to render * move bubble_event into render, move (raf) task handing into its own file * expect-error did hide that one --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Simon H <[email protected]>
1 parent 187400b commit 29890bb

File tree

23 files changed

+947
-934
lines changed

23 files changed

+947
-934
lines changed

packages/svelte/src/internal/client/block.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1+
import {
2+
ROOT_BLOCK,
3+
HEAD_BLOCK,
4+
DYNAMIC_ELEMENT_BLOCK,
5+
DYNAMIC_COMPONENT_BLOCK,
6+
SNIPPET_BLOCK
7+
} from './constants.js';
18
import { current_block } from './runtime.js';
29

3-
export const ROOT_BLOCK = 0;
4-
export const IF_BLOCK = 1;
5-
export const EACH_BLOCK = 2;
6-
export const EACH_ITEM_BLOCK = 3;
7-
export const AWAIT_BLOCK = 4;
8-
export const KEY_BLOCK = 5;
9-
export const HEAD_BLOCK = 6;
10-
export const DYNAMIC_COMPONENT_BLOCK = 7;
11-
export const DYNAMIC_ELEMENT_BLOCK = 8;
12-
export const SNIPPET_BLOCK = 9;
13-
1410
/**
1511
* @param {boolean} intro
1612
* @returns {import('./types.js').RootBlock}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const SOURCE = 1;
2+
export const DERIVED = 1 << 1;
3+
export const EFFECT = 1 << 2;
4+
export const PRE_EFFECT = 1 << 3;
5+
export const RENDER_EFFECT = 1 << 4;
6+
export const MANAGED = 1 << 6;
7+
export const UNOWNED = 1 << 7;
8+
export const CLEAN = 1 << 8;
9+
export const DIRTY = 1 << 9;
10+
export const MAYBE_DIRTY = 1 << 10;
11+
export const INERT = 1 << 11;
12+
export const DESTROYED = 1 << 12;
13+
14+
export const ROOT_BLOCK = 0;
15+
export const IF_BLOCK = 1;
16+
export const EACH_BLOCK = 2;
17+
export const EACH_ITEM_BLOCK = 3;
18+
export const AWAIT_BLOCK = 4;
19+
export const KEY_BLOCK = 5;
20+
export const HEAD_BLOCK = 6;
21+
export const DYNAMIC_COMPONENT_BLOCK = 7;
22+
export const DYNAMIC_ELEMENT_BLOCK = 8;
23+
export const SNIPPET_BLOCK = 9;
24+
25+
export const UNINITIALIZED = Symbol();
26+
export const STATE_SYMBOL = Symbol('$state');

packages/svelte/src/internal/client/custom-element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createClassComponent } from '../../legacy/legacy-client.js';
2-
import { render_effect, destroy_signal } from './runtime.js';
2+
import { destroy_signal } from './runtime.js';
3+
import { render_effect } from './reactivity/computations.js';
34
import { open, close } from './render.js';
45
import { define_property } from './utils.js';
56

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @typedef {{ file: string, line: number, column: number }} Location */
22

3-
import { STATE_SYMBOL } from '../proxy.js';
3+
import { STATE_SYMBOL } from '../constants.js';
44
import { untrack } from '../runtime.js';
55

66
/** @type {Record<string, Array<{ start: Location, end: Location, component: Function }>>} */

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { is_promise } from '../../../common.js';
2-
import { AWAIT_BLOCK } from '../../block.js';
32
import { hydrate_block_anchor } from '../../hydration.js';
43
import { remove } from '../../reconciler.js';
54
import {
6-
UNINITIALIZED,
75
current_block,
86
destroy_signal,
97
execute_effect,
108
flushSync,
11-
push_destroy_fn,
12-
render_effect
9+
push_destroy_fn
1310
} from '../../runtime.js';
11+
import { render_effect } from '../../reactivity/computations.js';
1412
import { trigger_transitions } from '../../transitions.js';
13+
import { AWAIT_BLOCK, UNINITIALIZED } from '../../constants.js';
1514

1615
/** @returns {import('../../types.js').AwaitBlock} */
1716
export function create_await_block() {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
EACH_KEYED
88
} from '../../../../constants.js';
99
import { noop } from '../../../common.js';
10-
import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../block.js';
1110
import {
1211
current_hydration_fragment,
1312
get_hydration_fragment,
@@ -21,14 +20,14 @@ import {
2120
current_block,
2221
destroy_signal,
2322
execute_effect,
24-
mutable_source,
2523
push_destroy_fn,
26-
render_effect,
27-
set_signal_value,
28-
source
24+
set_signal_value
2925
} from '../../runtime.js';
26+
import { render_effect } from '../../reactivity/computations.js';
27+
import { source, mutable_source } from '../../reactivity/sources.js';
3028
import { trigger_transitions } from '../../transitions.js';
3129
import { is_array } from '../../utils.js';
30+
import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js';
3231

3332
const NEW_BLOCK = -1;
3433
const MOVED_BLOCK = 99999999;

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { IF_BLOCK } from '../../block.js';
1+
import { IF_BLOCK } from '../../constants.js';
22
import {
33
current_hydration_fragment,
44
hydrate_block_anchor,
55
hydrating,
66
set_current_hydration_fragment
77
} from '../../hydration.js';
88
import { remove } from '../../reconciler.js';
9-
import {
10-
current_block,
11-
destroy_signal,
12-
execute_effect,
13-
push_destroy_fn,
14-
render_effect
15-
} from '../../runtime.js';
9+
import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js';
10+
import { render_effect } from '../../reactivity/computations.js';
1611
import { trigger_transitions } from '../../transitions.js';
1712

1813
/** @returns {import('../../types.js').IfBlock} */

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { KEY_BLOCK } from '../../block.js';
1+
import { UNINITIALIZED, KEY_BLOCK } from '../../constants.js';
22
import { hydrate_block_anchor } from '../../hydration.js';
33
import { remove } from '../../reconciler.js';
4-
import {
5-
UNINITIALIZED,
6-
current_block,
7-
destroy_signal,
8-
execute_effect,
9-
push_destroy_fn,
10-
render_effect,
11-
safe_not_equal
12-
} from '../../runtime.js';
4+
import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js';
5+
import { render_effect } from '../../reactivity/computations.js';
136
import { trigger_transitions } from '../../transitions.js';
7+
import { safe_not_equal } from '../../reactivity/equality.js';
148

159
/** @returns {import('../../types.js').KeyBlock} */
1610
function create_key_block() {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { run_all } from '../../common.js';
2+
3+
let is_task_queued = false;
4+
let is_raf_queued = false;
5+
6+
/** @type {Array<() => void>} */
7+
let current_queued_tasks = [];
8+
/** @type {Array<() => void>} */
9+
let current_raf_tasks = [];
10+
11+
function process_task() {
12+
is_task_queued = false;
13+
const tasks = current_queued_tasks.slice();
14+
current_queued_tasks = [];
15+
run_all(tasks);
16+
}
17+
18+
function process_raf_task() {
19+
is_raf_queued = false;
20+
const tasks = current_raf_tasks.slice();
21+
current_raf_tasks = [];
22+
run_all(tasks);
23+
}
24+
25+
/**
26+
* @param {() => void} fn
27+
* @returns {void}
28+
*/
29+
export function schedule_task(fn) {
30+
if (!is_task_queued) {
31+
is_task_queued = true;
32+
setTimeout(process_task, 0);
33+
}
34+
current_queued_tasks.push(fn);
35+
}
36+
37+
/**
38+
* @param {() => void} fn
39+
* @returns {void}
40+
*/
41+
export function schedule_raf_task(fn) {
42+
if (!is_raf_queued) {
43+
is_raf_queued = true;
44+
requestAnimationFrame(process_raf_task);
45+
}
46+
current_raf_tasks.push(fn);
47+
}
48+
49+
/**
50+
* Synchronously run any queued tasks.
51+
*/
52+
export function flush_tasks() {
53+
if (is_task_queued) {
54+
process_task();
55+
}
56+
if (is_raf_queued) {
57+
process_raf_task();
58+
}
59+
}

packages/svelte/src/internal/client/hydration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Handle hydration
22

3+
import { schedule_task } from './dom/task.js';
34
import { empty } from './operations.js';
4-
import { schedule_task } from './runtime.js';
55

66
/**
77
* Use this variable to guard everything related to hydration code so it can be treeshaken out

packages/svelte/src/internal/client/proxy.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { DEV } from 'esm-env';
22
import {
3-
effect_active,
43
get,
54
set,
65
update,
7-
source,
86
updating_derived,
9-
UNINITIALIZED,
10-
mutable_source,
117
batch_inspect,
128
current_component_context
139
} from './runtime.js';
10+
import { effect_active } from './reactivity/computations.js';
1411
import {
1512
array_prototype,
1613
define_property,
@@ -22,8 +19,8 @@ import {
2219
object_prototype
2320
} from './utils.js';
2421
import { add_owner, check_ownership, strip_owner } from './dev/ownership.js';
25-
26-
export const STATE_SYMBOL = Symbol('$state');
22+
import { mutable_source, source } from './reactivity/sources.js';
23+
import { STATE_SYMBOL, UNINITIALIZED } from './constants.js';
2724

2825
/**
2926
* @template T

0 commit comments

Comments
 (0)