ripple 0.3.25 → 0.3.26
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 +38 -0
- package/package.json +5 -5
- package/src/runtime/index-client.js +4 -0
- package/src/runtime/internal/client/hmr.js +1 -1
- package/src/runtime/internal/client/hydration.js +14 -0
- package/src/runtime/internal/client/runtime.js +127 -31
- package/src/runtime/internal/client/types.d.ts +3 -33
- package/src/runtime/internal/server/blocks.js +21 -1
- package/src/runtime/internal/server/index.js +299 -34
- package/src/runtime/internal/server/types.d.ts +3 -31
- package/src/runtime/reactive-value.js +1 -0
- package/src/utils/escaping.js +11 -0
- package/src/utils/track-async-serialization.js +9 -0
- package/tests/client/async-suspend.test.tsrx +11 -1
- package/tests/client/compiler/compiler.basic.test.tsrx +18 -3
- package/tests/client/track-async-hydration.test.tsrx +54 -0
- package/tests/hydration/compiled/client/basic.js +1 -1
- package/tests/hydration/compiled/client/events.js +8 -8
- package/tests/hydration/compiled/client/for.js +22 -24
- package/tests/hydration/compiled/client/head.js +6 -6
- package/tests/hydration/compiled/client/hmr.js +1 -1
- package/tests/hydration/compiled/client/html.js +1 -1
- package/tests/hydration/compiled/client/if-children.js +7 -7
- package/tests/hydration/compiled/client/if.js +5 -5
- package/tests/hydration/compiled/client/mixed-control-flow.js +4 -4
- package/tests/hydration/compiled/client/portal.js +1 -1
- package/tests/hydration/compiled/client/reactivity.js +9 -9
- package/tests/hydration/compiled/client/return.js +23 -23
- package/tests/hydration/compiled/client/switch.js +4 -4
- package/tests/hydration/compiled/client/track-async-serialization.js +390 -0
- package/tests/hydration/compiled/client/try.js +2 -2
- package/tests/hydration/compiled/server/basic.js +1 -1
- package/tests/hydration/compiled/server/events.js +8 -8
- package/tests/hydration/compiled/server/for.js +34 -28
- package/tests/hydration/compiled/server/head.js +6 -6
- package/tests/hydration/compiled/server/hmr.js +1 -1
- package/tests/hydration/compiled/server/html.js +1 -1
- package/tests/hydration/compiled/server/if-children.js +7 -7
- package/tests/hydration/compiled/server/if.js +5 -5
- package/tests/hydration/compiled/server/mixed-control-flow.js +4 -4
- package/tests/hydration/compiled/server/portal.js +1 -1
- package/tests/hydration/compiled/server/reactivity.js +9 -9
- package/tests/hydration/compiled/server/return.js +11 -11
- package/tests/hydration/compiled/server/switch.js +4 -4
- package/tests/hydration/compiled/server/track-async-serialization.js +502 -0
- package/tests/hydration/compiled/server/try.js +2 -2
- package/tests/hydration/components/track-async-serialization.tsrx +116 -0
- package/tests/hydration/track-async-serialization.test.js +127 -0
- package/tests/server/track-async-serialization.test.tsrx +185 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import * as _$_ from 'ripple/internal/server';
|
|
3
|
+
|
|
4
|
+
import { track, trackAsync } from 'ripple/server';
|
|
5
|
+
|
|
6
|
+
export const _$_server_$_ = (() => {
|
|
7
|
+
var _$_server_$_ = {};
|
|
8
|
+
|
|
9
|
+
_$_server_$_.formatValue = async function formatValue(n) {
|
|
10
|
+
return `server-${n}`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return _$_server_$_;
|
|
14
|
+
})();
|
|
15
|
+
|
|
16
|
+
export function AsyncWithServerCall() {
|
|
17
|
+
_$_.push_component();
|
|
18
|
+
|
|
19
|
+
let lazy = _$_.track(0, '2e21cbe9');
|
|
20
|
+
|
|
21
|
+
_$_.regular_block(() => {
|
|
22
|
+
_$_.output_push('<button');
|
|
23
|
+
_$_.output_push(' class="increment"');
|
|
24
|
+
_$_.output_push('>');
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
_$_.output_push('increment');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_$_.output_push('</button>');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
_$_.try_block(
|
|
34
|
+
() => {
|
|
35
|
+
_$_.output_push('<!--[-->');
|
|
36
|
+
|
|
37
|
+
let lazy_1 = _$_.track_async(() => _$_server_$_.formatValue(_$_.get(lazy)), 'f0c2b41e');
|
|
38
|
+
|
|
39
|
+
_$_.regular_block(() => {
|
|
40
|
+
_$_.output_push('<p');
|
|
41
|
+
_$_.output_push(' class="result"');
|
|
42
|
+
_$_.output_push('>');
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_1)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_$_.output_push('</p>');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
_$_.output_push('<!--]-->');
|
|
52
|
+
},
|
|
53
|
+
null,
|
|
54
|
+
() => {
|
|
55
|
+
_$_.output_push('<!--[-->');
|
|
56
|
+
|
|
57
|
+
_$_.regular_block(() => {
|
|
58
|
+
_$_.output_push('<p');
|
|
59
|
+
_$_.output_push(' class="loading"');
|
|
60
|
+
_$_.output_push('>');
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
_$_.output_push('loading...');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_$_.output_push('</p>');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
_$_.output_push('<!--]-->');
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
_$_.pop_component();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function AsyncSimpleValue() {
|
|
77
|
+
_$_.push_component();
|
|
78
|
+
|
|
79
|
+
_$_.try_block(
|
|
80
|
+
() => {
|
|
81
|
+
_$_.output_push('<!--[-->');
|
|
82
|
+
|
|
83
|
+
let lazy_2 = _$_.track_async(() => Promise.resolve('hydrated value'), '4e502c38');
|
|
84
|
+
|
|
85
|
+
_$_.regular_block(() => {
|
|
86
|
+
_$_.output_push('<p');
|
|
87
|
+
_$_.output_push(' class="result"');
|
|
88
|
+
_$_.output_push('>');
|
|
89
|
+
|
|
90
|
+
{
|
|
91
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_2)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_$_.output_push('</p>');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
_$_.output_push('<!--]-->');
|
|
98
|
+
},
|
|
99
|
+
null,
|
|
100
|
+
() => {
|
|
101
|
+
_$_.output_push('<!--[-->');
|
|
102
|
+
|
|
103
|
+
_$_.regular_block(() => {
|
|
104
|
+
_$_.output_push('<p');
|
|
105
|
+
_$_.output_push(' class="loading"');
|
|
106
|
+
_$_.output_push('>');
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
_$_.output_push('loading...');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_$_.output_push('</p>');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
_$_.output_push('<!--]-->');
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
_$_.pop_component();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function AsyncNumericValue() {
|
|
123
|
+
_$_.push_component();
|
|
124
|
+
|
|
125
|
+
_$_.try_block(
|
|
126
|
+
() => {
|
|
127
|
+
_$_.output_push('<!--[-->');
|
|
128
|
+
|
|
129
|
+
let lazy_3 = _$_.track_async(() => Promise.resolve(42), '14891754');
|
|
130
|
+
|
|
131
|
+
_$_.regular_block(() => {
|
|
132
|
+
_$_.output_push('<span');
|
|
133
|
+
_$_.output_push(' class="count"');
|
|
134
|
+
_$_.output_push('>');
|
|
135
|
+
|
|
136
|
+
{
|
|
137
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_3)));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_$_.output_push('</span>');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
_$_.output_push('<!--]-->');
|
|
144
|
+
},
|
|
145
|
+
null,
|
|
146
|
+
() => {
|
|
147
|
+
_$_.output_push('<!--[-->');
|
|
148
|
+
|
|
149
|
+
_$_.regular_block(() => {
|
|
150
|
+
_$_.output_push('<span');
|
|
151
|
+
_$_.output_push(' class="pending"');
|
|
152
|
+
_$_.output_push('>');
|
|
153
|
+
|
|
154
|
+
{
|
|
155
|
+
_$_.output_push('...');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
_$_.output_push('</span>');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
_$_.output_push('<!--]-->');
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
_$_.pop_component();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function AsyncObjectValue() {
|
|
169
|
+
_$_.push_component();
|
|
170
|
+
|
|
171
|
+
_$_.try_block(
|
|
172
|
+
() => {
|
|
173
|
+
_$_.output_push('<!--[-->');
|
|
174
|
+
|
|
175
|
+
let lazy_4 = _$_.track_async(() => Promise.resolve({ name: 'Alice', age: 30 }), 'f325448a');
|
|
176
|
+
|
|
177
|
+
_$_.regular_block(() => {
|
|
178
|
+
_$_.output_push('<div');
|
|
179
|
+
_$_.output_push(' class="user"');
|
|
180
|
+
_$_.output_push('>');
|
|
181
|
+
|
|
182
|
+
{
|
|
183
|
+
_$_.output_push('<span');
|
|
184
|
+
_$_.output_push(' class="name"');
|
|
185
|
+
_$_.output_push('>');
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_4).name));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_$_.output_push('</span>');
|
|
192
|
+
_$_.output_push('<span');
|
|
193
|
+
_$_.output_push(' class="age"');
|
|
194
|
+
_$_.output_push('>');
|
|
195
|
+
|
|
196
|
+
{
|
|
197
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_4).age));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
_$_.output_push('</span>');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_$_.output_push('</div>');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
_$_.output_push('<!--]-->');
|
|
207
|
+
},
|
|
208
|
+
null,
|
|
209
|
+
() => {
|
|
210
|
+
_$_.output_push('<!--[-->');
|
|
211
|
+
|
|
212
|
+
_$_.regular_block(() => {
|
|
213
|
+
_$_.output_push('<div');
|
|
214
|
+
_$_.output_push(' class="loading"');
|
|
215
|
+
_$_.output_push('>');
|
|
216
|
+
|
|
217
|
+
{
|
|
218
|
+
_$_.output_push('loading user...');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_$_.output_push('</div>');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
_$_.output_push('<!--]-->');
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
_$_.pop_component();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function AsyncMultipleValues() {
|
|
232
|
+
_$_.push_component();
|
|
233
|
+
|
|
234
|
+
_$_.try_block(
|
|
235
|
+
() => {
|
|
236
|
+
_$_.output_push('<!--[-->');
|
|
237
|
+
|
|
238
|
+
let lazy_5 = _$_.track_async(() => Promise.resolve('alpha'), 'ab8199a0');
|
|
239
|
+
let lazy_6 = _$_.track_async(() => Promise.resolve('beta'), 'fb7ad40b');
|
|
240
|
+
|
|
241
|
+
_$_.regular_block(() => {
|
|
242
|
+
_$_.output_push('<div');
|
|
243
|
+
_$_.output_push(' class="multi"');
|
|
244
|
+
_$_.output_push('>');
|
|
245
|
+
|
|
246
|
+
{
|
|
247
|
+
_$_.output_push('<span');
|
|
248
|
+
_$_.output_push(' class="first"');
|
|
249
|
+
_$_.output_push('>');
|
|
250
|
+
|
|
251
|
+
{
|
|
252
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_5)));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_$_.output_push('</span>');
|
|
256
|
+
_$_.output_push('<span');
|
|
257
|
+
_$_.output_push(' class="second"');
|
|
258
|
+
_$_.output_push('>');
|
|
259
|
+
|
|
260
|
+
{
|
|
261
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_6)));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_$_.output_push('</span>');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_$_.output_push('</div>');
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
_$_.output_push('<!--]-->');
|
|
271
|
+
},
|
|
272
|
+
null,
|
|
273
|
+
() => {
|
|
274
|
+
_$_.output_push('<!--[-->');
|
|
275
|
+
|
|
276
|
+
_$_.regular_block(() => {
|
|
277
|
+
_$_.output_push('<div');
|
|
278
|
+
_$_.output_push(' class="loading"');
|
|
279
|
+
_$_.output_push('>');
|
|
280
|
+
|
|
281
|
+
{
|
|
282
|
+
_$_.output_push('loading...');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
_$_.output_push('</div>');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
_$_.output_push('<!--]-->');
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
_$_.pop_component();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function AsyncWithCatch() {
|
|
296
|
+
_$_.push_component();
|
|
297
|
+
|
|
298
|
+
_$_.try_block(
|
|
299
|
+
() => {
|
|
300
|
+
_$_.output_push('<!--[-->');
|
|
301
|
+
|
|
302
|
+
let lazy_7 = _$_.track_async(() => Promise.reject(new Error('fetch failed')), '99982de5');
|
|
303
|
+
|
|
304
|
+
_$_.regular_block(() => {
|
|
305
|
+
_$_.output_push('<p');
|
|
306
|
+
_$_.output_push(' class="result"');
|
|
307
|
+
_$_.output_push('>');
|
|
308
|
+
|
|
309
|
+
{
|
|
310
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_7)));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
_$_.output_push('</p>');
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
_$_.output_push('<!--]-->');
|
|
317
|
+
},
|
|
318
|
+
(e) => {
|
|
319
|
+
_$_.output_push('<!--[-->');
|
|
320
|
+
|
|
321
|
+
_$_.regular_block(() => {
|
|
322
|
+
_$_.output_push('<p');
|
|
323
|
+
_$_.output_push(' class="error"');
|
|
324
|
+
_$_.output_push('>');
|
|
325
|
+
|
|
326
|
+
{
|
|
327
|
+
_$_.output_push(_$_.escape(e.message));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
_$_.output_push('</p>');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
_$_.output_push('<!--]-->');
|
|
334
|
+
},
|
|
335
|
+
() => {
|
|
336
|
+
_$_.output_push('<!--[-->');
|
|
337
|
+
|
|
338
|
+
_$_.regular_block(() => {
|
|
339
|
+
_$_.output_push('<p');
|
|
340
|
+
_$_.output_push(' class="loading"');
|
|
341
|
+
_$_.output_push('>');
|
|
342
|
+
|
|
343
|
+
{
|
|
344
|
+
_$_.output_push('loading...');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
_$_.output_push('</p>');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
_$_.output_push('<!--]-->');
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
_$_.pop_component();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function ChildWithError() {
|
|
358
|
+
_$_.push_component();
|
|
359
|
+
|
|
360
|
+
_$_.try_block(
|
|
361
|
+
() => {
|
|
362
|
+
_$_.output_push('<!--[-->');
|
|
363
|
+
|
|
364
|
+
let lazy_8 = _$_.track_async(() => Promise.reject(new Error('child error')), '1dea4c85');
|
|
365
|
+
|
|
366
|
+
_$_.regular_block(() => {
|
|
367
|
+
_$_.output_push('<p');
|
|
368
|
+
_$_.output_push(' class="result"');
|
|
369
|
+
_$_.output_push('>');
|
|
370
|
+
|
|
371
|
+
{
|
|
372
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_8)));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
_$_.output_push('</p>');
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
_$_.output_push('<!--]-->');
|
|
379
|
+
},
|
|
380
|
+
null,
|
|
381
|
+
() => {
|
|
382
|
+
_$_.output_push('<!--[-->');
|
|
383
|
+
|
|
384
|
+
_$_.regular_block(() => {
|
|
385
|
+
_$_.output_push('<p');
|
|
386
|
+
_$_.output_push(' class="pending"');
|
|
387
|
+
_$_.output_push('>');
|
|
388
|
+
|
|
389
|
+
{
|
|
390
|
+
_$_.output_push('loading...');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
_$_.output_push('</p>');
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
_$_.output_push('<!--]-->');
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
_$_.pop_component();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function ParentWithCatch() {
|
|
404
|
+
_$_.push_component();
|
|
405
|
+
|
|
406
|
+
_$_.try_block(
|
|
407
|
+
() => {
|
|
408
|
+
_$_.output_push('<!--[-->');
|
|
409
|
+
|
|
410
|
+
_$_.regular_block(() => {
|
|
411
|
+
{
|
|
412
|
+
const comp = ChildWithError;
|
|
413
|
+
const args = [{}];
|
|
414
|
+
|
|
415
|
+
comp(...args);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
_$_.output_push('<!--]-->');
|
|
420
|
+
},
|
|
421
|
+
(e) => {
|
|
422
|
+
_$_.output_push('<!--[-->');
|
|
423
|
+
|
|
424
|
+
_$_.regular_block(() => {
|
|
425
|
+
_$_.output_push('<p');
|
|
426
|
+
_$_.output_push(' class="parent-error"');
|
|
427
|
+
_$_.output_push('>');
|
|
428
|
+
|
|
429
|
+
{
|
|
430
|
+
_$_.output_push(_$_.escape(e.message));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
_$_.output_push('</p>');
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
_$_.output_push('<!--]-->');
|
|
437
|
+
},
|
|
438
|
+
null
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
_$_.pop_component();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export function AsyncWithReactiveDependency() {
|
|
445
|
+
_$_.push_component();
|
|
446
|
+
|
|
447
|
+
let lazy_9 = _$_.track(0, 'c9d12acf');
|
|
448
|
+
|
|
449
|
+
_$_.regular_block(() => {
|
|
450
|
+
_$_.output_push('<button');
|
|
451
|
+
_$_.output_push(' class="increment"');
|
|
452
|
+
_$_.output_push('>');
|
|
453
|
+
|
|
454
|
+
{
|
|
455
|
+
_$_.output_push('increment');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
_$_.output_push('</button>');
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
_$_.try_block(
|
|
462
|
+
() => {
|
|
463
|
+
_$_.output_push('<!--[-->');
|
|
464
|
+
|
|
465
|
+
let lazy_10 = _$_.track_async(() => Promise.resolve(`count-${_$_.get(lazy_9)}`), 'cdd1adb8');
|
|
466
|
+
|
|
467
|
+
_$_.regular_block(() => {
|
|
468
|
+
_$_.output_push('<p');
|
|
469
|
+
_$_.output_push(' class="result"');
|
|
470
|
+
_$_.output_push('>');
|
|
471
|
+
|
|
472
|
+
{
|
|
473
|
+
_$_.output_push(_$_.escape(_$_.get(lazy_10)));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
_$_.output_push('</p>');
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
_$_.output_push('<!--]-->');
|
|
480
|
+
},
|
|
481
|
+
null,
|
|
482
|
+
() => {
|
|
483
|
+
_$_.output_push('<!--[-->');
|
|
484
|
+
|
|
485
|
+
_$_.regular_block(() => {
|
|
486
|
+
_$_.output_push('<p');
|
|
487
|
+
_$_.output_push(' class="loading"');
|
|
488
|
+
_$_.output_push('>');
|
|
489
|
+
|
|
490
|
+
{
|
|
491
|
+
_$_.output_push('loading...');
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
_$_.output_push('</p>');
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
_$_.output_push('<!--]-->');
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
_$_.pop_component();
|
|
502
|
+
}
|
|
@@ -47,7 +47,7 @@ export function AsyncListInTryPending() {
|
|
|
47
47
|
function AsyncList() {
|
|
48
48
|
_$_.push_component();
|
|
49
49
|
|
|
50
|
-
let lazy = _$_.track_async(() => Promise.resolve(['alpha', 'beta', 'gamma']));
|
|
50
|
+
let lazy = _$_.track_async(() => Promise.resolve(['alpha', 'beta', 'gamma']), 'd6bf9e33');
|
|
51
51
|
|
|
52
52
|
_$_.regular_block(() => {
|
|
53
53
|
_$_.output_push('<ul');
|
|
@@ -133,7 +133,7 @@ export function AsyncTryWithLeadingSibling() {
|
|
|
133
133
|
function AsyncContent() {
|
|
134
134
|
_$_.push_component();
|
|
135
135
|
|
|
136
|
-
let lazy_1 = _$_.track_async(() => Promise.resolve('ready'));
|
|
136
|
+
let lazy_1 = _$_.track_async(() => Promise.resolve('ready'), 'd2fe7b64');
|
|
137
137
|
|
|
138
138
|
_$_.regular_block(() => {
|
|
139
139
|
_$_.output_push('<div');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { track, trackAsync } from 'ripple';
|
|
2
|
+
|
|
3
|
+
#server {
|
|
4
|
+
export async function formatValue(n: number): Promise<string> {
|
|
5
|
+
return `server-${n}`;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export component AsyncWithServerCall() {
|
|
10
|
+
let &[count] = track(0);
|
|
11
|
+
|
|
12
|
+
<button
|
|
13
|
+
class="increment"
|
|
14
|
+
onClick={() => {
|
|
15
|
+
count++;
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
{'increment'}
|
|
19
|
+
</button>
|
|
20
|
+
try {
|
|
21
|
+
let &[data] = trackAsync(() => #server.formatValue(count));
|
|
22
|
+
<p class="result">{data}</p>
|
|
23
|
+
} pending {
|
|
24
|
+
<p class="loading">{'loading...'}</p>
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export component AsyncSimpleValue() {
|
|
29
|
+
try {
|
|
30
|
+
let &[data] = trackAsync(() => Promise.resolve('hydrated value'));
|
|
31
|
+
<p class="result">{data}</p>
|
|
32
|
+
} pending {
|
|
33
|
+
<p class="loading">{'loading...'}</p>
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export component AsyncNumericValue() {
|
|
38
|
+
try {
|
|
39
|
+
let &[count] = trackAsync(() => Promise.resolve(42));
|
|
40
|
+
<span class="count">{count}</span>
|
|
41
|
+
} pending {
|
|
42
|
+
<span class="pending">{'...'}</span>
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export component AsyncObjectValue() {
|
|
47
|
+
try {
|
|
48
|
+
let &[user] = trackAsync(() => Promise.resolve({ name: 'Alice', age: 30 }));
|
|
49
|
+
<div class="user">
|
|
50
|
+
<span class="name">{user.name}</span>
|
|
51
|
+
<span class="age">{user.age}</span>
|
|
52
|
+
</div>
|
|
53
|
+
} pending {
|
|
54
|
+
<div class="loading">{'loading user...'}</div>
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export component AsyncMultipleValues() {
|
|
59
|
+
try {
|
|
60
|
+
let &[first] = trackAsync(() => Promise.resolve('alpha'));
|
|
61
|
+
let &[second] = trackAsync(() => Promise.resolve('beta'));
|
|
62
|
+
<div class="multi">
|
|
63
|
+
<span class="first">{first}</span>
|
|
64
|
+
<span class="second">{second}</span>
|
|
65
|
+
</div>
|
|
66
|
+
} pending {
|
|
67
|
+
<div class="loading">{'loading...'}</div>
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export component AsyncWithCatch() {
|
|
72
|
+
try {
|
|
73
|
+
let &[data] = trackAsync(() => Promise.reject(new Error('fetch failed')));
|
|
74
|
+
<p class="result">{data}</p>
|
|
75
|
+
} pending {
|
|
76
|
+
<p class="loading">{'loading...'}</p>
|
|
77
|
+
} catch (e) {
|
|
78
|
+
<p class="error">{(e as Error).message}</p>
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export component ChildWithError() {
|
|
83
|
+
try {
|
|
84
|
+
let &[data] = trackAsync(() => Promise.reject(new Error('child error')));
|
|
85
|
+
<p class="result">{data}</p>
|
|
86
|
+
} pending {
|
|
87
|
+
<p class="pending">{'loading...'}</p>
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export component ParentWithCatch() {
|
|
92
|
+
try {
|
|
93
|
+
<ChildWithError />
|
|
94
|
+
} catch (e) {
|
|
95
|
+
<p class="parent-error">{(e as Error).message}</p>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export component AsyncWithReactiveDependency() {
|
|
100
|
+
let &[count] = track(0);
|
|
101
|
+
|
|
102
|
+
<button
|
|
103
|
+
class="increment"
|
|
104
|
+
onClick={() => {
|
|
105
|
+
count++;
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{'increment'}
|
|
109
|
+
</button>
|
|
110
|
+
try {
|
|
111
|
+
let &[data] = trackAsync(() => Promise.resolve(`count-${count}`));
|
|
112
|
+
<p class="result">{data}</p>
|
|
113
|
+
} pending {
|
|
114
|
+
<p class="loading">{'loading...'}</p>
|
|
115
|
+
}
|
|
116
|
+
}
|