ripple 0.3.128 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +267 -0
- package/package.json +10 -4
- package/src/runtime/element.js +23 -6
- package/src/runtime/index-client.js +81 -41
- package/src/runtime/index-server.js +1 -0
- package/src/runtime/internal/client/blocks.js +173 -91
- package/src/runtime/internal/client/component.js +4 -30
- package/src/runtime/internal/client/composite.js +12 -13
- package/src/runtime/internal/client/constants.js +9 -0
- package/src/runtime/internal/client/context.js +12 -19
- package/src/runtime/internal/client/css.js +7 -9
- package/src/runtime/internal/client/events.js +178 -90
- package/src/runtime/internal/client/expression.js +45 -25
- package/src/runtime/internal/client/for.js +409 -129
- package/src/runtime/internal/client/head.js +10 -5
- package/src/runtime/internal/client/html.js +1 -0
- package/src/runtime/internal/client/hydration.js +152 -10
- package/src/runtime/internal/client/if.js +239 -50
- package/src/runtime/internal/client/index.js +4 -12
- package/src/runtime/internal/client/operations.js +40 -61
- package/src/runtime/internal/client/portal.js +163 -85
- package/src/runtime/internal/client/render.js +39 -39
- package/src/runtime/internal/client/rpc.js +3 -3
- package/src/runtime/internal/client/runtime.js +592 -433
- package/src/runtime/internal/client/selector.js +5 -2
- package/src/runtime/internal/client/template.js +133 -158
- package/src/runtime/internal/client/transport.js +38 -0
- package/src/runtime/internal/client/try.js +465 -426
- package/src/runtime/internal/client/types.d.ts +56 -23
- package/src/runtime/internal/client/utils.js +1 -3
- package/src/runtime/internal/server/dynamic.js +20 -21
- package/src/runtime/internal/server/index.js +325 -275
- package/src/runtime/internal/server/rpc.js +3 -2
- package/src/runtime/internal/server/transport.js +16 -0
- package/src/runtime/transport.js +21 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +0 -5
- package/tests/client/array/array.copy-within.test.tsrx +12 -12
- package/tests/client/array/array.derived.test.tsrx +46 -46
- package/tests/client/array/array.iteration.test.tsrx +10 -10
- package/tests/client/array/array.mutations.test.tsrx +20 -20
- package/tests/client/array/array.static.test.tsrx +11 -11
- package/tests/client/array/array.to-methods.test.tsrx +6 -6
- package/tests/client/async-suspend.test.tsrx +74 -75
- package/tests/client/basic/basic.attributes.test.tsrx +86 -83
- package/tests/client/basic/basic.collections.test.tsrx +12 -12
- package/tests/client/basic/basic.components.test.tsrx +99 -25
- package/tests/client/basic/basic.errors.test.tsrx +18 -18
- package/tests/client/basic/basic.events.test.tsrx +42 -42
- package/tests/client/basic/basic.get-set.test.tsrx +8 -8
- package/tests/client/basic/basic.reactivity.test.tsrx +73 -38
- package/tests/client/basic/basic.rendering.test.tsrx +25 -25
- package/tests/client/basic/basic.utilities.test.tsrx +3 -3
- package/tests/client/boundaries.test.tsrx +8 -8
- package/tests/client/boxed-locals.test.tsrx +452 -0
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +6 -6
- package/tests/client/compiler/compiler.assignments.test.tsrx +9 -73
- package/tests/client/compiler/compiler.attributes.test.tsrx +23 -23
- package/tests/client/compiler/compiler.basic.test.tsrx +15 -60
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +18 -43
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +2 -2
- package/tests/client/composite/__snapshots__/composite.render.test.tsrx.snap +0 -1
- package/tests/client/composite/composite.dynamic-components.test.tsrx +77 -6
- package/tests/client/composite/composite.props.test.tsrx +149 -12
- package/tests/client/composite/composite.reactivity.test.tsrx +51 -52
- package/tests/client/composite/composite.render.test.tsrx +26 -9
- package/tests/client/css/scoped-styles.test.tsrx +8 -8
- package/tests/client/date.test.tsrx +42 -42
- package/tests/client/derived-release.test.tsrx +370 -0
- package/tests/client/dynamic-elements.test.tsrx +45 -45
- package/tests/client/events.test.tsrx +97 -71
- package/tests/client/for-selector.test.tsrx +14 -14
- package/tests/client/for-single-root-items.test.tsrx +118 -3
- package/tests/client/for.test.tsrx +332 -31
- package/tests/client/head.test.tsrx +19 -19
- package/tests/client/html.test.tsrx +11 -9
- package/tests/client/if-block.test.tsrx +80 -0
- package/tests/client/map.test.tsrx +16 -16
- package/tests/client/media-query.test.tsrx +7 -7
- package/tests/client/portal.test.tsrx +224 -26
- package/tests/client/primitive-text.test.tsrx +50 -0
- package/tests/client/prop-kind-switch.test.tsrx +141 -0
- package/tests/client/ref.test.tsrx +17 -17
- package/tests/client/return.test.tsrx +26 -3
- package/tests/client/root-boundary.test.tsrx +42 -0
- package/tests/client/scoped-flush.test.tsrx +8 -8
- package/tests/client/set.test.tsrx +6 -6
- package/tests/client/svg.test.tsrx +11 -11
- package/tests/client/switch.test.tsrx +44 -44
- package/tests/client/track-async-hydration.test.tsrx +4 -4
- package/tests/client/try.test.tsrx +151 -83
- package/tests/client/tsx.test.tsrx +43 -40
- package/tests/client/url/url.derived.test.tsrx +6 -6
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +18 -18
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +2 -2
- package/tests/hydration/basic.test.js +74 -1
- package/tests/hydration/build-components.js +22 -1
- package/tests/hydration/compiled/client/basic.js +1142 -713
- package/tests/hydration/compiled/client/composite.js +151 -100
- package/tests/hydration/compiled/client/events.js +184 -171
- package/tests/hydration/compiled/client/for.js +1472 -1132
- package/tests/hydration/compiled/client/fragment-cursor.js +2341 -0
- package/tests/hydration/compiled/client/head.js +254 -201
- package/tests/hydration/compiled/client/hmr.js +54 -41
- package/tests/hydration/compiled/client/html-in-template.js +54 -39
- package/tests/hydration/compiled/client/html.js +1633 -1263
- package/tests/hydration/compiled/client/if-children.js +420 -270
- package/tests/hydration/compiled/client/if-fragment-controlflow.js +363 -317
- package/tests/hydration/compiled/client/if.js +229 -219
- package/tests/hydration/compiled/client/mixed-control-flow.js +420 -404
- package/tests/hydration/compiled/client/nested-control-flow.js +1326 -1277
- package/tests/hydration/compiled/client/portal.js +87 -95
- package/tests/hydration/compiled/client/reactivity.js +135 -101
- package/tests/hydration/compiled/client/return.js +28 -19
- package/tests/hydration/compiled/client/streaming.js +390 -306
- package/tests/hydration/compiled/client/switch.js +258 -266
- package/tests/hydration/compiled/client/track-async-serialization.js +448 -280
- package/tests/hydration/compiled/client/try.js +173 -129
- package/tests/hydration/compiled/client/typed-text.js +71 -0
- package/tests/hydration/compiled/fixtures/money.js +10 -0
- package/tests/hydration/compiled/server/basic.js +123 -6
- package/tests/hydration/compiled/server/composite.js +16 -30
- package/tests/hydration/compiled/server/events.js +66 -18
- package/tests/hydration/compiled/server/for.js +117 -41
- package/tests/hydration/compiled/server/fragment-cursor.js +1687 -0
- package/tests/hydration/compiled/server/head.js +20 -20
- package/tests/hydration/compiled/server/hmr.js +2 -2
- package/tests/hydration/compiled/server/html.js +70 -238
- package/tests/hydration/compiled/server/if-children.js +107 -15
- package/tests/hydration/compiled/server/if.js +11 -15
- package/tests/hydration/compiled/server/mixed-control-flow.js +8 -8
- package/tests/hydration/compiled/server/portal.js +14 -22
- package/tests/hydration/compiled/server/reactivity.js +14 -14
- package/tests/hydration/compiled/server/streaming.js +19 -19
- package/tests/hydration/compiled/server/switch.js +8 -8
- package/tests/hydration/compiled/server/track-async-serialization.js +150 -23
- package/tests/hydration/compiled/server/try.js +8 -8
- package/tests/hydration/compiled/server/typed-text.js +17 -0
- package/tests/hydration/components/basic.tsrx +44 -8
- package/tests/hydration/components/composite.tsrx +2 -2
- package/tests/hydration/components/events.tsrx +25 -25
- package/tests/hydration/components/for.tsrx +115 -67
- package/tests/hydration/components/fragment-cursor.tsrx +650 -0
- package/tests/hydration/components/head.tsrx +16 -16
- package/tests/hydration/components/hmr.tsrx +2 -2
- package/tests/hydration/components/html.tsrx +7 -7
- package/tests/hydration/components/if-children.tsrx +72 -25
- package/tests/hydration/components/if.tsrx +18 -18
- package/tests/hydration/components/mixed-control-flow.tsrx +11 -11
- package/tests/hydration/components/portal.tsrx +3 -3
- package/tests/hydration/components/reactivity.tsrx +16 -16
- package/tests/hydration/components/streaming.tsrx +20 -20
- package/tests/hydration/components/switch.tsrx +20 -20
- package/tests/hydration/components/text-types.ts +4 -0
- package/tests/hydration/components/track-async-serialization.tsrx +80 -26
- package/tests/hydration/components/try.tsrx +8 -8
- package/tests/hydration/components/typed-text.tsrx +22 -0
- package/tests/hydration/fixtures/money.js +10 -0
- package/tests/hydration/for.test.js +36 -0
- package/tests/hydration/fragment-cursor.test.js +111 -0
- package/tests/hydration/if-children.test.js +24 -0
- package/tests/hydration/streaming.test.js +19 -0
- package/tests/hydration/track-async-serialization.test.js +87 -2
- package/tests/hydration/tsconfig.text-types.json +10 -0
- package/tests/hydration/typed-text.test.js +34 -0
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +42 -42
- package/tests/server/basic.components.test.tsrx +64 -8
- package/tests/server/basic.test.tsrx +34 -32
- package/tests/server/compiler.test.tsrx +1 -70
- package/tests/server/composite.props.test.tsrx +6 -6
- package/tests/server/dynamic-elements.test.tsrx +31 -8
- package/tests/server/for.test.tsrx +94 -0
- package/tests/server/head.test.tsrx +11 -11
- package/tests/server/scoped-styles.test.tsrx +2 -2
- package/tests/server/streaming-ssr.test.tsrx +48 -43
- package/tests/server/track-async-serialization.test.tsrx +204 -21
- package/tests/server/try.test.tsrx +48 -48
- package/tests/types/transport.ts +40 -0
- package/tests/utils/vite-plugin-config.test.js +23 -0
- package/types/index.d.ts +48 -7
- package/types/server.d.ts +3 -0
- package/types/transport.d.ts +15 -0
- package/src/runtime/internal/client/switch.js +0 -113
- package/src/utils/errors.js +0 -13
- package/tests/client/lazy-array.test.tsrx +0 -31
- package/tests/client/lazy-destructuring.test.tsrx +0 -438
- package/tests/client/tracked-index-access.test.tsrx +0 -113
- package/tests/server/lazy-destructuring.test.tsrx +0 -595
- package/tests/server/tracked-index-access.test.tsrx +0 -76
|
@@ -47,14 +47,14 @@ describe('RippleArray > static', () => {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function ArrayTest() @{
|
|
50
|
-
|
|
50
|
+
const items = trackAsync(() => RippleArray.fromAsync([1, 2, 3]));
|
|
51
51
|
<>
|
|
52
52
|
<button
|
|
53
53
|
onClick={() => {
|
|
54
|
-
items.push(4);
|
|
54
|
+
items.value.push(4);
|
|
55
55
|
}}
|
|
56
56
|
>{'add item'}</button>
|
|
57
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
57
|
+
<pre>{JSON.stringify(items.value)}</pre>
|
|
58
58
|
</>
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -84,14 +84,14 @@ describe('RippleArray > static', () => {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function ArrayTest() @{
|
|
87
|
-
|
|
87
|
+
const items = trackAsync(() => RippleArray.fromAsync([1, 2, 3], (x: number) => x * 2));
|
|
88
88
|
<>
|
|
89
89
|
<button
|
|
90
90
|
onClick={() => {
|
|
91
|
-
items.push(8);
|
|
91
|
+
items.value.push(8);
|
|
92
92
|
}}
|
|
93
93
|
>{'add item'}</button>
|
|
94
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
94
|
+
<pre>{JSON.stringify(items.value)}</pre>
|
|
95
95
|
</>
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -127,10 +127,10 @@ describe('RippleArray > static', () => {
|
|
|
127
127
|
throw new Error('Async error');
|
|
128
128
|
}
|
|
129
129
|
@try {
|
|
130
|
-
|
|
130
|
+
const items = trackAsync(() => RippleArray.fromAsync(throwingIterable()));
|
|
131
131
|
|
|
132
132
|
<ul>
|
|
133
|
-
@for (const item of items) {
|
|
133
|
+
@for (const item of items.value) {
|
|
134
134
|
<li>{item}</li>
|
|
135
135
|
}
|
|
136
136
|
</ul>
|
|
@@ -231,10 +231,10 @@ describe('RippleArray > static', () => {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
function ArrayTest() @{
|
|
234
|
-
|
|
234
|
+
const items = trackAsync(() => RippleArray.fromAsync([6]));
|
|
235
235
|
<>
|
|
236
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
237
|
-
<pre>{items.length}</pre>
|
|
236
|
+
<pre>{JSON.stringify(items.value)}</pre>
|
|
237
|
+
<pre>{items.value.length}</pre>
|
|
238
238
|
</>
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -8,11 +8,11 @@ describe('RippleArray > to* methods', () => {
|
|
|
8
8
|
|
|
9
9
|
function ArrayTest() @{
|
|
10
10
|
let items = new RippleArray(1, 2, 3, 4);
|
|
11
|
-
|
|
11
|
+
const reversed = track(() => items.toReversed());
|
|
12
12
|
<>
|
|
13
13
|
<button onClick={() => items.push(5)}>{'add item'}</button>
|
|
14
14
|
<pre>{JSON.stringify(items)}</pre>
|
|
15
|
-
<pre>{JSON.stringify(reversed)}</pre>
|
|
15
|
+
<pre>{JSON.stringify(reversed.value)}</pre>
|
|
16
16
|
</>
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -39,11 +39,11 @@ describe('RippleArray > to* methods', () => {
|
|
|
39
39
|
|
|
40
40
|
function ArrayTest() @{
|
|
41
41
|
let items = new RippleArray(3, 1, 4, 2);
|
|
42
|
-
|
|
42
|
+
const sorted = track(() => items.toSorted());
|
|
43
43
|
<>
|
|
44
44
|
<button onClick={() => items.push(0)}>{'add item'}</button>
|
|
45
45
|
<pre>{JSON.stringify(items)}</pre>
|
|
46
|
-
<pre>{JSON.stringify(sorted)}</pre>
|
|
46
|
+
<pre>{JSON.stringify(sorted.value)}</pre>
|
|
47
47
|
</>
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -70,11 +70,11 @@ describe('RippleArray > to* methods', () => {
|
|
|
70
70
|
|
|
71
71
|
function ArrayTest() @{
|
|
72
72
|
let items = new RippleArray<string | number>(1, 2, 3, 4, 5);
|
|
73
|
-
|
|
73
|
+
const spliced = track(() => items.toSpliced(1, 2, 'a', 'b'));
|
|
74
74
|
<>
|
|
75
75
|
<button onClick={() => (items[2] = 30)}>{'change item'}</button>
|
|
76
76
|
<pre>{JSON.stringify(items)}</pre>
|
|
77
|
-
<pre>{JSON.stringify(spliced)}</pre>
|
|
77
|
+
<pre>{JSON.stringify(spliced.value)}</pre>
|
|
78
78
|
</>
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -5,9 +5,9 @@ describe('async suspense', () => {
|
|
|
5
5
|
it('hides child content during re-suspension when tracked dependency changes', async () => {
|
|
6
6
|
let resolve_fn: (() => void) | null = null;
|
|
7
7
|
|
|
8
|
-
function Child({
|
|
8
|
+
function Child({ count }: { count: Tracked<number> }) @{
|
|
9
9
|
trackAsync(() => {
|
|
10
|
-
|
|
10
|
+
count.value;
|
|
11
11
|
return new Promise<void>((resolve) => {
|
|
12
12
|
resolve_fn = resolve;
|
|
13
13
|
});
|
|
@@ -16,20 +16,20 @@ describe('async suspense', () => {
|
|
|
16
16
|
<div class="child-content">{'child content'}</div>
|
|
17
17
|
<div class="count">
|
|
18
18
|
{'count is: '}
|
|
19
|
-
{
|
|
19
|
+
{count.value}
|
|
20
20
|
</div>
|
|
21
21
|
</>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function App() @{
|
|
25
|
-
|
|
25
|
+
const count = track(0);
|
|
26
26
|
<>
|
|
27
27
|
@try {
|
|
28
|
-
<Child {
|
|
28
|
+
<Child {count} />
|
|
29
29
|
} @pending {
|
|
30
30
|
<div class="pending">{'pending...'}</div>
|
|
31
31
|
}
|
|
32
|
-
<button onClick={() => count++}>{'Increment'}</button>
|
|
32
|
+
<button onClick={() => count.value++}>{'Increment'}</button>
|
|
33
33
|
</>
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -70,19 +70,19 @@ describe('async suspense', () => {
|
|
|
70
70
|
let resolve_value: ((value: string) => void) | null = null;
|
|
71
71
|
|
|
72
72
|
function Child() @{
|
|
73
|
-
|
|
73
|
+
const value = trackAsync(
|
|
74
74
|
() => new Promise<string>((resolve) => {
|
|
75
75
|
resolve_value = resolve;
|
|
76
76
|
}),
|
|
77
77
|
);
|
|
78
|
-
<div class="value">{value}</div>
|
|
78
|
+
<div class="value">{value.value}</div>
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function App() @{
|
|
82
|
-
|
|
82
|
+
const show = track(true);
|
|
83
83
|
<>
|
|
84
|
-
<button onClick={() => (show = false)}>{'Hide'}</button>
|
|
85
|
-
@if (show) {
|
|
84
|
+
<button onClick={() => (show.value = false)}>{'Hide'}</button>
|
|
85
|
+
@if (show.value) {
|
|
86
86
|
@try {
|
|
87
87
|
<Child />
|
|
88
88
|
} @pending {
|
|
@@ -138,11 +138,11 @@ describe('async suspense', () => {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
function App() @{
|
|
141
|
-
|
|
141
|
+
const query = track('a');
|
|
142
142
|
<>
|
|
143
143
|
@try {
|
|
144
|
-
|
|
145
|
-
<div class="value">{value}</div>
|
|
144
|
+
const value = trackAsync(() => createRequest(query.value));
|
|
145
|
+
<div class="value">{value.value}</div>
|
|
146
146
|
} @pending {
|
|
147
147
|
<div class="pending">{'loading...'}</div>
|
|
148
148
|
} @catch (error) {
|
|
@@ -150,7 +150,7 @@ describe('async suspense', () => {
|
|
|
150
150
|
}
|
|
151
151
|
<button
|
|
152
152
|
onClick={() => {
|
|
153
|
-
query = query === 'a' ? 'b' : 'c';
|
|
153
|
+
query.value = query.value === 'a' ? 'b' : 'c';
|
|
154
154
|
}}
|
|
155
155
|
>{'Next'}</button>
|
|
156
156
|
</>
|
|
@@ -196,36 +196,35 @@ describe('async suspense', () => {
|
|
|
196
196
|
async () => {
|
|
197
197
|
let pending_render_count = 0;
|
|
198
198
|
|
|
199
|
-
function FilteredList({
|
|
200
|
-
|
|
201
|
-
let &[items] = trackAsync(
|
|
199
|
+
function FilteredList({ query }: { query: Tracked<string> }) @{
|
|
200
|
+
const items = trackAsync(
|
|
202
201
|
() => Promise.resolve(
|
|
203
|
-
!query ? ['apple', 'banana', 'cherry'] : ['avocado', 'blueberry', 'citrus'],
|
|
202
|
+
!query.value ? ['apple', 'banana', 'cherry'] : ['avocado', 'blueberry', 'citrus'],
|
|
204
203
|
),
|
|
205
204
|
);
|
|
206
|
-
|
|
207
|
-
return items.filter((item: string) => item.includes(query));
|
|
205
|
+
const filtered = track(() => {
|
|
206
|
+
return items.value.filter((item: string) => item.includes(query.value));
|
|
208
207
|
});
|
|
209
208
|
<>
|
|
210
209
|
<ul>
|
|
211
|
-
@for (let item of filtered) {
|
|
210
|
+
@for (let item of filtered.value) {
|
|
212
211
|
<li>{item}</li>
|
|
213
212
|
}
|
|
214
213
|
</ul>
|
|
215
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
214
|
+
<pre>{JSON.stringify(items.value)}</pre>
|
|
216
215
|
</>
|
|
217
216
|
}
|
|
218
217
|
|
|
219
218
|
function App() @{
|
|
220
|
-
|
|
219
|
+
const query = track('');
|
|
221
220
|
<>
|
|
222
221
|
@try {
|
|
223
|
-
<FilteredList {
|
|
222
|
+
<FilteredList {query} />
|
|
224
223
|
} @pending {
|
|
225
224
|
pending_render_count += 1;
|
|
226
225
|
<p class="pending">{'loading...'}</p>
|
|
227
226
|
}
|
|
228
|
-
<button onClick={() => (query = 'a')}>{'Search'}</button>
|
|
227
|
+
<button onClick={() => (query.value = 'a')}>{'Search'}</button>
|
|
229
228
|
</>
|
|
230
229
|
}
|
|
231
230
|
|
|
@@ -271,32 +270,32 @@ describe('async suspense', () => {
|
|
|
271
270
|
let pending_render_count = 0;
|
|
272
271
|
|
|
273
272
|
function App() @{
|
|
274
|
-
|
|
273
|
+
const query = track('');
|
|
275
274
|
<>
|
|
276
275
|
@try {
|
|
277
|
-
|
|
276
|
+
const items = trackAsync(
|
|
278
277
|
() => Promise.resolve(
|
|
279
|
-
!query ? ['apple', 'banana', 'cherry'] : ['avocado', 'blueberry', 'citrus'],
|
|
278
|
+
!query.value ? ['apple', 'banana', 'cherry'] : ['avocado', 'blueberry', 'citrus'],
|
|
280
279
|
),
|
|
281
280
|
);
|
|
282
281
|
|
|
283
|
-
|
|
284
|
-
return items.filter((item: string) => item.includes(query));
|
|
282
|
+
const filtered = track(() => {
|
|
283
|
+
return items.value.filter((item: string) => item.includes(query.value));
|
|
285
284
|
});
|
|
286
285
|
|
|
287
286
|
<>
|
|
288
287
|
<ul>
|
|
289
|
-
@for (let item of filtered) {
|
|
288
|
+
@for (let item of filtered.value) {
|
|
290
289
|
<li>{item}</li>
|
|
291
290
|
}
|
|
292
291
|
</ul>
|
|
293
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
292
|
+
<pre>{JSON.stringify(items.value)}</pre>
|
|
294
293
|
</>
|
|
295
294
|
} @pending {
|
|
296
295
|
pending_render_count += 1;
|
|
297
296
|
<p class="pending">{'loading...'}</p>
|
|
298
297
|
}
|
|
299
|
-
<button onClick={() => (query = 'a')}>{'Search'}</button>
|
|
298
|
+
<button onClick={() => (query.value = 'a')}>{'Search'}</button>
|
|
300
299
|
</>
|
|
301
300
|
}
|
|
302
301
|
|
|
@@ -336,45 +335,45 @@ describe('async suspense', () => {
|
|
|
336
335
|
let double_effect_runs = 0;
|
|
337
336
|
let quadruple_effect_runs = 0;
|
|
338
337
|
let times_rendered = 0;
|
|
339
|
-
function Child(
|
|
340
|
-
const
|
|
341
|
-
const result = count * 2;
|
|
338
|
+
function Child({ count }: { count: Tracked<number> }) @{
|
|
339
|
+
const double = trackAsync(() => {
|
|
340
|
+
const result = count.value * 2;
|
|
342
341
|
|
|
343
342
|
return new Promise<number>((resolve) => {
|
|
344
343
|
resolve_double = () => resolve(result);
|
|
345
344
|
});
|
|
346
345
|
});
|
|
347
|
-
const
|
|
348
|
-
const result = double * 2;
|
|
346
|
+
const quadruple = trackAsync(() => {
|
|
347
|
+
const result = double.value * 2;
|
|
349
348
|
|
|
350
349
|
return new Promise<number>((resolve) => {
|
|
351
350
|
resolve_quadruple = () => resolve(result);
|
|
352
351
|
});
|
|
353
352
|
});
|
|
354
353
|
effect(() => {
|
|
355
|
-
double;
|
|
354
|
+
double.value;
|
|
356
355
|
double_effect_runs += 1;
|
|
357
356
|
});
|
|
358
357
|
effect(() => {
|
|
359
|
-
quadruple;
|
|
358
|
+
quadruple.value;
|
|
360
359
|
quadruple_effect_runs += 1;
|
|
361
360
|
});
|
|
362
361
|
// this is to make the times_rendered render together with double
|
|
363
362
|
<>
|
|
364
|
-
<div class="double">{double + (++times_rendered - times_rendered)}</div>
|
|
365
|
-
<div class="quadruple">{quadruple}</div>
|
|
363
|
+
<div class="double">{double.value + (++times_rendered - times_rendered)}</div>
|
|
364
|
+
<div class="quadruple">{quadruple.value}</div>
|
|
366
365
|
</>
|
|
367
366
|
}
|
|
368
367
|
|
|
369
368
|
function App() @{
|
|
370
|
-
|
|
369
|
+
const count = track(2);
|
|
371
370
|
<>
|
|
372
371
|
@try {
|
|
373
372
|
<Child {count} />
|
|
374
373
|
} @pending {
|
|
375
374
|
<div class="pending">{'Loading...'}</div>
|
|
376
375
|
}
|
|
377
|
-
<button onClick={() => count++}>{'Increment'}</button>
|
|
376
|
+
<button onClick={() => count.value++}>{'Increment'}</button>
|
|
378
377
|
</>
|
|
379
378
|
}
|
|
380
379
|
|
|
@@ -429,45 +428,45 @@ describe('async suspense', () => {
|
|
|
429
428
|
let double_effect_runs = 0;
|
|
430
429
|
let quadruple_effect_runs = 0;
|
|
431
430
|
let times_rendered = 0;
|
|
432
|
-
function Child(
|
|
433
|
-
const
|
|
434
|
-
const result = count * 2;
|
|
431
|
+
function Child({ count }: { count: Tracked<number> }) @{
|
|
432
|
+
const double = trackAsync(() => {
|
|
433
|
+
const result = count.value * 2;
|
|
435
434
|
|
|
436
435
|
return new Promise<number>((resolve) => {
|
|
437
436
|
resolve_double = () => resolve(result);
|
|
438
437
|
});
|
|
439
438
|
});
|
|
440
|
-
const
|
|
441
|
-
const result = double * 2;
|
|
439
|
+
const quadruple = trackAsync(() => {
|
|
440
|
+
const result = double.value * 2;
|
|
442
441
|
|
|
443
442
|
return new Promise<number>((resolve) => {
|
|
444
443
|
resolve_quadruple = () => resolve(result);
|
|
445
444
|
});
|
|
446
445
|
});
|
|
447
446
|
effect(() => {
|
|
448
|
-
double;
|
|
447
|
+
double.value;
|
|
449
448
|
double_effect_runs += 1;
|
|
450
449
|
});
|
|
451
450
|
effect(() => {
|
|
452
|
-
quadruple;
|
|
451
|
+
quadruple.value;
|
|
453
452
|
quadruple_effect_runs += 1;
|
|
454
453
|
});
|
|
455
454
|
// this is to make the times_rendered render together with double
|
|
456
455
|
<>
|
|
457
|
-
<div class="double">{double + (++times_rendered - times_rendered)}</div>
|
|
458
|
-
<div class="quadruple">{quadruple}</div>
|
|
456
|
+
<div class="double">{double.value + (++times_rendered - times_rendered)}</div>
|
|
457
|
+
<div class="quadruple">{quadruple.value}</div>
|
|
459
458
|
</>
|
|
460
459
|
}
|
|
461
460
|
|
|
462
461
|
function App() @{
|
|
463
|
-
|
|
462
|
+
const count = track(2);
|
|
464
463
|
<>
|
|
465
464
|
@try {
|
|
466
465
|
<Child {count} />
|
|
467
466
|
} @pending {
|
|
468
467
|
<div class="pending">{'Loading...'}</div>
|
|
469
468
|
}
|
|
470
|
-
<button onClick={() => count++}>{'Increment'}</button>
|
|
469
|
+
<button onClick={() => count.value++}>{'Increment'}</button>
|
|
471
470
|
</>
|
|
472
471
|
}
|
|
473
472
|
|
|
@@ -520,16 +519,16 @@ describe('async suspense', () => {
|
|
|
520
519
|
|
|
521
520
|
it('resolves chained async values without explicit flushSync', async () => {
|
|
522
521
|
let times_rendered = 0;
|
|
523
|
-
function Child(
|
|
524
|
-
const
|
|
522
|
+
function Child({ count }: { count: number }) @{
|
|
523
|
+
const double = trackAsync(() => {
|
|
525
524
|
const result = count * 2;
|
|
526
525
|
|
|
527
526
|
return new Promise<number>((resolve) => {
|
|
528
527
|
setTimeout(() => resolve(result), 0);
|
|
529
528
|
});
|
|
530
529
|
});
|
|
531
|
-
const
|
|
532
|
-
const result = double * 2;
|
|
530
|
+
const quadruple = trackAsync(() => {
|
|
531
|
+
const result = double.value * 2;
|
|
533
532
|
|
|
534
533
|
return new Promise<number>((resolve) => {
|
|
535
534
|
setTimeout(() => resolve(result), 0);
|
|
@@ -537,17 +536,17 @@ describe('async suspense', () => {
|
|
|
537
536
|
});
|
|
538
537
|
// this is to make the times_rendered render together with double
|
|
539
538
|
<>
|
|
540
|
-
<div class="double">{double + (++times_rendered - times_rendered)}</div>
|
|
541
|
-
<div class="quadruple">{quadruple}</div>
|
|
539
|
+
<div class="double">{double.value + (++times_rendered - times_rendered)}</div>
|
|
540
|
+
<div class="quadruple">{quadruple.value}</div>
|
|
542
541
|
</>
|
|
543
542
|
}
|
|
544
543
|
|
|
545
544
|
function App() @{
|
|
546
|
-
|
|
545
|
+
const count = track(0);
|
|
547
546
|
<>
|
|
548
|
-
<button onClick={() => count++}>{count}</button>
|
|
547
|
+
<button onClick={() => count.value++}>{count.value}</button>
|
|
549
548
|
@try {
|
|
550
|
-
<Child {count} />
|
|
549
|
+
<Child count={count.value} />
|
|
551
550
|
} @pending {
|
|
552
551
|
<div class="pending">{'Loading...'}</div>
|
|
553
552
|
}
|
|
@@ -579,11 +578,11 @@ describe('async suspense', () => {
|
|
|
579
578
|
async () => {
|
|
580
579
|
let resolve_fn: ((value: string[]) => void) | null = null;
|
|
581
580
|
|
|
582
|
-
function Child({
|
|
581
|
+
function Child({ items }: { items: Tracked<string[]> }) @{
|
|
583
582
|
@try {
|
|
584
583
|
<div class="child-content">
|
|
585
584
|
{'child: '}
|
|
586
|
-
{
|
|
585
|
+
{items.value.join(', ')}
|
|
587
586
|
</div>
|
|
588
587
|
} @pending {
|
|
589
588
|
<div class="child-pending">{'child loading...'}</div>
|
|
@@ -591,11 +590,11 @@ describe('async suspense', () => {
|
|
|
591
590
|
}
|
|
592
591
|
|
|
593
592
|
function App() @{
|
|
594
|
-
|
|
593
|
+
const query = track('initial');
|
|
595
594
|
<>
|
|
596
595
|
@try {
|
|
597
|
-
|
|
598
|
-
const q = query;
|
|
596
|
+
const items = trackAsync(() => {
|
|
597
|
+
const q = query.value;
|
|
599
598
|
return new Promise<string[]>((resolve) => {
|
|
600
599
|
resolve_fn = resolve;
|
|
601
600
|
});
|
|
@@ -604,14 +603,14 @@ describe('async suspense', () => {
|
|
|
604
603
|
<>
|
|
605
604
|
<div class="parent-content">
|
|
606
605
|
{'parent: '}
|
|
607
|
-
{items.join(', ')}
|
|
606
|
+
{items.value.join(', ')}
|
|
608
607
|
</div>
|
|
609
|
-
<Child {
|
|
608
|
+
<Child {items} />
|
|
610
609
|
</>
|
|
611
610
|
} @pending {
|
|
612
611
|
<div class="parent-pending">{'parent loading...'}</div>
|
|
613
612
|
}
|
|
614
|
-
<button onClick={() => (query = 'next')}>{'Change'}</button>
|
|
613
|
+
<button onClick={() => (query.value = 'next')}>{'Change'}</button>
|
|
615
614
|
</>
|
|
616
615
|
}
|
|
617
616
|
|
|
@@ -657,8 +656,8 @@ describe('async suspense', () => {
|
|
|
657
656
|
|
|
658
657
|
it('uses the root pending boundary when trackAsync has no local try/pending boundary', () => {
|
|
659
658
|
function App() @{
|
|
660
|
-
|
|
661
|
-
<div>{value}</div>
|
|
659
|
+
const value = trackAsync(() => Promise.resolve('test'));
|
|
660
|
+
<div>{value.value}</div>
|
|
662
661
|
}
|
|
663
662
|
|
|
664
663
|
expect(() => {
|