@warp-drive/ember 5.8.0-beta.0 → 5.8.0-beta.1
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/README.md +37 -16
- package/declarations/-private/await.d.ts +7 -7
- package/declarations/-private/request.d.ts +7 -6
- package/declarations/index.d.ts +3 -210
- package/dist/index.js +14 -13
- package/dist/unpkg/dev/index.js +466 -0
- package/dist/unpkg/dev/install.js +49 -0
- package/dist/unpkg/dev-deprecated/index.js +466 -0
- package/dist/unpkg/dev-deprecated/install.js +80 -0
- package/dist/unpkg/prod/index.js +455 -0
- package/dist/unpkg/prod/install.js +36 -0
- package/dist/unpkg/prod-deprecated/index.js +455 -0
- package/dist/unpkg/prod-deprecated/install.js +67 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +15 -7
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { service } from '@ember/service';
|
|
2
|
+
import Component from '@glimmer/component';
|
|
3
|
+
import { getPromiseState, createRequestSubscription } from '@warp-drive/core/reactive';
|
|
4
|
+
export { createRequestSubscription, getPromiseState, getRequestState } from '@warp-drive/core/reactive';
|
|
5
|
+
import { DISPOSE, memoized } from '@warp-drive/core/signals/-leaked';
|
|
6
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
7
|
+
import { setComponentTemplate } from '@ember/component';
|
|
8
|
+
import templateOnly from '@ember/component/template-only';
|
|
9
|
+
|
|
10
|
+
const and = (x, y) => Boolean(x && y);
|
|
11
|
+
/**
|
|
12
|
+
* The `<Throw />` component is used to throw an error in a template.
|
|
13
|
+
*
|
|
14
|
+
* That's all it does. So don't use it unless the application should
|
|
15
|
+
* throw an error if it reaches this point in the template.
|
|
16
|
+
*
|
|
17
|
+
* ```gts
|
|
18
|
+
* <Throw @error={{anError}} />
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @category Components
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class Throw extends Component {
|
|
25
|
+
constructor(owner, args) {
|
|
26
|
+
super(owner, args);
|
|
27
|
+
// this error is opaque (user supplied) so we don't validate it
|
|
28
|
+
// as an Error instance.
|
|
29
|
+
|
|
30
|
+
{
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
32
|
+
throw this.args.error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
setComponentTemplate(precompileTemplate("", {
|
|
37
|
+
strictMode: true
|
|
38
|
+
}), this);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `<Await />` component allow you to utilize reactive control flow
|
|
43
|
+
* for asynchronous states in your application.
|
|
44
|
+
*
|
|
45
|
+
* Await is ideal for handling "boundaries", outside which some state is
|
|
46
|
+
* still allowed to be unresolved and within which it MUST be resolved.
|
|
47
|
+
*
|
|
48
|
+
* ```gts
|
|
49
|
+
* import { Await } from '@warp-drive/ember';
|
|
50
|
+
*
|
|
51
|
+
* <template>
|
|
52
|
+
* <Await @promise={{@request}}>
|
|
53
|
+
* <:pending>
|
|
54
|
+
* <Spinner />
|
|
55
|
+
* </:pending>
|
|
56
|
+
*
|
|
57
|
+
* <:error as |error|>
|
|
58
|
+
* <ErrorForm @error={{error}} />
|
|
59
|
+
* </:error>
|
|
60
|
+
*
|
|
61
|
+
* <:success as |result|>
|
|
62
|
+
* <h1>{{result.title}}</h1>
|
|
63
|
+
* </:success>
|
|
64
|
+
* </Await>
|
|
65
|
+
* </template>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* The `<Await />` component requires that error states are properly handled.
|
|
69
|
+
*
|
|
70
|
+
* If no error block is provided and the promise rejects, the error will
|
|
71
|
+
* be thrown.
|
|
72
|
+
*
|
|
73
|
+
* @category Components
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
class Await extends Component {
|
|
77
|
+
get state() {
|
|
78
|
+
return getPromiseState(this.args.promise);
|
|
79
|
+
}
|
|
80
|
+
get error() {
|
|
81
|
+
return this.state.error;
|
|
82
|
+
}
|
|
83
|
+
get result() {
|
|
84
|
+
return this.state.result;
|
|
85
|
+
}
|
|
86
|
+
static {
|
|
87
|
+
setComponentTemplate(precompileTemplate("\n {{#if this.state.isPending}}\n {{yield to=\"pending\"}}\n {{else if (and this.state.isError (has-block \"error\"))}}\n {{yield this.error to=\"error\"}}\n {{else if this.state.isSuccess}}\n {{yield this.result to=\"success\"}}\n {{else}}\n <Throw @error={{this.error}} />\n {{/if}}\n ", {
|
|
88
|
+
strictMode: true,
|
|
89
|
+
scope: () => ({
|
|
90
|
+
and,
|
|
91
|
+
Throw
|
|
92
|
+
})
|
|
93
|
+
}), this);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const deferred = /* @__PURE__ */new WeakMap();
|
|
98
|
+
function deferDecorator(proto, prop, desc) {
|
|
99
|
+
let map = deferred.get(proto);
|
|
100
|
+
if (!map) {
|
|
101
|
+
map = /* @__PURE__ */new Map();
|
|
102
|
+
deferred.set(proto, map);
|
|
103
|
+
}
|
|
104
|
+
map.set(prop, desc);
|
|
105
|
+
}
|
|
106
|
+
function findDeferredDecorator(target, prop) {
|
|
107
|
+
var _a;
|
|
108
|
+
let cursor = target.prototype;
|
|
109
|
+
while (cursor) {
|
|
110
|
+
let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);
|
|
111
|
+
if (desc) {
|
|
112
|
+
return desc;
|
|
113
|
+
}
|
|
114
|
+
cursor = cursor.prototype;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function decorateFieldV2(prototype, prop, decorators, initializer) {
|
|
118
|
+
let desc = {
|
|
119
|
+
configurable: true,
|
|
120
|
+
enumerable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
initializer: null
|
|
123
|
+
};
|
|
124
|
+
if (initializer) {
|
|
125
|
+
desc.initializer = initializer;
|
|
126
|
+
}
|
|
127
|
+
for (let decorator of decorators) {
|
|
128
|
+
desc = decorator(prototype, prop, desc) || desc;
|
|
129
|
+
}
|
|
130
|
+
if (desc.initializer === void 0) {
|
|
131
|
+
Object.defineProperty(prototype, prop, desc);
|
|
132
|
+
} else {
|
|
133
|
+
deferDecorator(prototype, prop, desc);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function decorateMethodV2(prototype, prop, decorators) {
|
|
137
|
+
const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
|
|
138
|
+
let desc = {
|
|
139
|
+
...origDesc
|
|
140
|
+
};
|
|
141
|
+
for (let decorator of decorators) {
|
|
142
|
+
desc = decorator(prototype, prop, desc) || desc;
|
|
143
|
+
}
|
|
144
|
+
if (desc.initializer !== void 0) {
|
|
145
|
+
desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
|
|
146
|
+
desc.initializer = void 0;
|
|
147
|
+
}
|
|
148
|
+
Object.defineProperty(prototype, prop, desc);
|
|
149
|
+
}
|
|
150
|
+
function initializeDeferredDecorator(target, prop) {
|
|
151
|
+
let desc = findDeferredDecorator(target.constructor, prop);
|
|
152
|
+
if (desc) {
|
|
153
|
+
Object.defineProperty(target, prop, {
|
|
154
|
+
enumerable: desc.enumerable,
|
|
155
|
+
configurable: desc.configurable,
|
|
156
|
+
writable: desc.writable,
|
|
157
|
+
value: desc.initializer ? desc.initializer.call(target) : void 0
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function notNull(x) {
|
|
163
|
+
(test => {
|
|
164
|
+
if (!test) {
|
|
165
|
+
throw new Error('Expected a non-null value, but got null');
|
|
166
|
+
}
|
|
167
|
+
})(x !== null);
|
|
168
|
+
return x;
|
|
169
|
+
}
|
|
170
|
+
const not = x => !x;
|
|
171
|
+
const IdleBlockMissingError = new Error('No idle block provided for <Request> component, and no query or request was provided.');
|
|
172
|
+
let consume = service;
|
|
173
|
+
const DefaultChrome = setComponentTemplate(precompileTemplate("{{yield}}", {
|
|
174
|
+
strictMode: true
|
|
175
|
+
}), templateOnly());
|
|
176
|
+
/**
|
|
177
|
+
* The `<Request />` component is a powerful tool for managing data fetching and
|
|
178
|
+
* state in your Ember application. It provides a declarative approach to reactive
|
|
179
|
+
* control-flow for managing requests and state in your application.
|
|
180
|
+
*
|
|
181
|
+
* The `<Request />` component is ideal for handling "boundaries", outside which some
|
|
182
|
+
* state is still allowed to be unresolved and within which it MUST be resolved.
|
|
183
|
+
*
|
|
184
|
+
* ## Request States
|
|
185
|
+
*
|
|
186
|
+
* `<Request />` has five states, only one of which will be active and rendered at a time.
|
|
187
|
+
*
|
|
188
|
+
* - `idle`: The component is waiting to be given a request to monitor
|
|
189
|
+
* - `loading`: The request is in progress
|
|
190
|
+
* - `error`: The request failed
|
|
191
|
+
* - `content`: The request succeeded
|
|
192
|
+
* - `cancelled`: The request was cancelled
|
|
193
|
+
*
|
|
194
|
+
* Additionally, the `content` state has a `refresh` method that can be used to
|
|
195
|
+
* refresh the request in the background, which is available as a sub-state of
|
|
196
|
+
* the `content` state.
|
|
197
|
+
*
|
|
198
|
+
* As with the `<Await />` component, if no error block is provided and the request
|
|
199
|
+
* rejects, the error will be thrown. Cancellation errors are swallowed instead of
|
|
200
|
+
* rethrown if no error block or cancellation block is present.
|
|
201
|
+
*
|
|
202
|
+
* ```gts
|
|
203
|
+
* import { Request } from '@warp-drive/ember';
|
|
204
|
+
*
|
|
205
|
+
* <template>
|
|
206
|
+
* <Request @request={{@request}}>
|
|
207
|
+
* <:loading as |state|>
|
|
208
|
+
* <Spinner @percentDone={{state.completedRatio}} />
|
|
209
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
210
|
+
* </:loading>
|
|
211
|
+
*
|
|
212
|
+
* <:error as |error state|>
|
|
213
|
+
* <ErrorForm @error={{error}} />
|
|
214
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
215
|
+
* </:error>
|
|
216
|
+
*
|
|
217
|
+
* <:content as |data state|>
|
|
218
|
+
* <h1>{{data.title}}</h1>
|
|
219
|
+
* {{#if state.isBackgroundReloading}}
|
|
220
|
+
* <SmallSpinner />
|
|
221
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
222
|
+
* {{else}}
|
|
223
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
224
|
+
* {{/if}}
|
|
225
|
+
* </:content>
|
|
226
|
+
*
|
|
227
|
+
* <:cancelled as |error state|>
|
|
228
|
+
* <h2>The Request was cancelled</h2>
|
|
229
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
230
|
+
* </:cancelled>
|
|
231
|
+
*
|
|
232
|
+
* <:idle>
|
|
233
|
+
* <button {{on "click" @kickOffRequest}}>Load Preview?</button>
|
|
234
|
+
* </:idle>
|
|
235
|
+
*
|
|
236
|
+
* </Request>
|
|
237
|
+
* </template>
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* ## Streaming Data
|
|
241
|
+
*
|
|
242
|
+
* The loading state exposes the download `ReadableStream` instance for consumption
|
|
243
|
+
*
|
|
244
|
+
* ```gts
|
|
245
|
+
* import { Request } from '@warp-drive/ember';
|
|
246
|
+
*
|
|
247
|
+
* <template>
|
|
248
|
+
* <Request @request={{@request}}>
|
|
249
|
+
* <:loading as |state|>
|
|
250
|
+
* <Video @stream={{state.stream}} />
|
|
251
|
+
* </:loading>
|
|
252
|
+
*
|
|
253
|
+
* <:error as |error|>
|
|
254
|
+
* <ErrorForm @error={{error}} />
|
|
255
|
+
* </:error>
|
|
256
|
+
* </Request>
|
|
257
|
+
* </template>
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* ## Retry
|
|
261
|
+
*
|
|
262
|
+
* Cancelled and error'd requests may be retried by calling the `retry` method.
|
|
263
|
+
*
|
|
264
|
+
* Retry will restart the state progression, using the loading, error, cancelled,
|
|
265
|
+
* and content blocks as appropriate.
|
|
266
|
+
*
|
|
267
|
+
* ## Reloading
|
|
268
|
+
*
|
|
269
|
+
* The `reload` method will force the request to be fully re-executed, bypassing
|
|
270
|
+
* cache and restarting the state progression through the loading, error, and
|
|
271
|
+
* content blocks as appropriate.
|
|
272
|
+
*
|
|
273
|
+
* Background reload (refresh) is a special substate of the content state that
|
|
274
|
+
* allows you to refresh the request in the background. This is useful for when
|
|
275
|
+
* you want to update the data in the background without blocking the UI.
|
|
276
|
+
*
|
|
277
|
+
* Reload and refresh are available as methods on the `content` state.
|
|
278
|
+
*
|
|
279
|
+
* ```gts
|
|
280
|
+
* import { Request } from '@warp-drive/ember';
|
|
281
|
+
*
|
|
282
|
+
* <template>
|
|
283
|
+
* <Request @request={{@request}}>
|
|
284
|
+
* <:content as |data state|>
|
|
285
|
+
* <h1>{{data.title}}</h1>
|
|
286
|
+
* {{#if state.isBackgroundReloading}}
|
|
287
|
+
* <SmallSpinner />
|
|
288
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
289
|
+
* {{/if}}
|
|
290
|
+
*
|
|
291
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
292
|
+
* <button {{on "click" state.reload}}>Reload</button>
|
|
293
|
+
* </:content>
|
|
294
|
+
* </Request>
|
|
295
|
+
* </template>
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* ## Advanced Reloading
|
|
299
|
+
*
|
|
300
|
+
* We can nest our usage of `<Request />` to handle more advanced
|
|
301
|
+
* reloading scenarios.
|
|
302
|
+
*
|
|
303
|
+
* ```gts
|
|
304
|
+
* import { Request } from '@warp-drive/ember';
|
|
305
|
+
*
|
|
306
|
+
* <template>
|
|
307
|
+
* <Request @request={{@request}}>
|
|
308
|
+
* <:cancelled>
|
|
309
|
+
* <h2>The Request Cancelled</h2>
|
|
310
|
+
* </:cancelled>
|
|
311
|
+
*
|
|
312
|
+
* <:error as |error|>
|
|
313
|
+
* <ErrorForm @error={{error}} />
|
|
314
|
+
* </:error>
|
|
315
|
+
*
|
|
316
|
+
* <:content as |result state|>
|
|
317
|
+
* <Request @request={{state.latestRequest}}>
|
|
318
|
+
* <!-- Handle Background Request -->
|
|
319
|
+
* </Request>
|
|
320
|
+
*
|
|
321
|
+
* <h1>{{result.title}}</h1>
|
|
322
|
+
*
|
|
323
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
324
|
+
* </:content>
|
|
325
|
+
* </Request>
|
|
326
|
+
* </template>
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* ## Autorefresh
|
|
330
|
+
*
|
|
331
|
+
* `<Request />` supports automatic refresh and reload under certain conditions.
|
|
332
|
+
*
|
|
333
|
+
* - `online`: This occurs when a browser window or tab comes back to the foreground
|
|
334
|
+
* after being backgrounded or when the network reports as being online after
|
|
335
|
+
* having been offline.
|
|
336
|
+
* - `interval`: This occurs when a specified amount of time has passed.
|
|
337
|
+
* - `invalid`: This occurs when the store emits a notification that the request
|
|
338
|
+
* has become invalid.
|
|
339
|
+
*
|
|
340
|
+
* You can specify when autorefresh should occur by setting the `autorefresh` arg
|
|
341
|
+
* to `true` or a comma-separated list of the above values.
|
|
342
|
+
*
|
|
343
|
+
* A value of `true` is equivalent to `'online,invalid'`.
|
|
344
|
+
*
|
|
345
|
+
* By default, an autorefresh will only occur if the browser was backgrounded or
|
|
346
|
+
* offline for more than 30s before coming back available. This amount of time can
|
|
347
|
+
* be tweaked by setting the number of milliseconds via `@autorefreshThreshold`.
|
|
348
|
+
*
|
|
349
|
+
* This arg also controls the interval at which the request will be refreshed
|
|
350
|
+
* if the `interval` autorefresh type is enabled.
|
|
351
|
+
*
|
|
352
|
+
* Finally, the behavior of the request initiated by autorefresh can be adjusted
|
|
353
|
+
* by setting the `autorefreshBehavior` arg to `'refresh'`, `'reload'`, or `'policy'`.
|
|
354
|
+
*
|
|
355
|
+
* - `'refresh'`: Refresh the request in the background
|
|
356
|
+
* - `'reload'`: Force a reload of the request
|
|
357
|
+
* - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to
|
|
358
|
+
* reload, refresh, or do nothing.
|
|
359
|
+
*
|
|
360
|
+
* More advanced refresh and reload behaviors can be created by passing the reload and
|
|
361
|
+
* refresh actions into another component. For instance, refresh could be set up on a
|
|
362
|
+
* timer or on a websocket subscription.
|
|
363
|
+
*
|
|
364
|
+
*
|
|
365
|
+
* ```gts
|
|
366
|
+
* import { Request } from '@warp-drive/ember';
|
|
367
|
+
*
|
|
368
|
+
* <template>
|
|
369
|
+
* <Request @request={{@request}}>
|
|
370
|
+
* <:content as |result state|>
|
|
371
|
+
* <h1>{{result.title}}</h1>
|
|
372
|
+
*
|
|
373
|
+
* <Interval @period={{30_000}} @fn={{state.refresh}} />
|
|
374
|
+
* <Subscribe @channel={{@someValue}} @fn={{state.refresh}} />
|
|
375
|
+
* </:content>
|
|
376
|
+
* </Request>
|
|
377
|
+
* </template>
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* If a matching request is refreshed or reloaded by any other component,
|
|
381
|
+
* the `Request` component will react accordingly.
|
|
382
|
+
*
|
|
383
|
+
* ## Deduping
|
|
384
|
+
*
|
|
385
|
+
* The store dedupes requests by identity. If a request is made for the same identity
|
|
386
|
+
* from multiple `<Request />` components, even if the request is not referentially the
|
|
387
|
+
* same, only one actual request will be made.
|
|
388
|
+
*
|
|
389
|
+
* @category Components
|
|
390
|
+
* @public
|
|
391
|
+
*/
|
|
392
|
+
class Request extends Component {
|
|
393
|
+
static {
|
|
394
|
+
decorateFieldV2(this.prototype, "_store", [consume('store')]);
|
|
395
|
+
}
|
|
396
|
+
#_store = (initializeDeferredDecorator(this, "_store"), void 0);
|
|
397
|
+
/**
|
|
398
|
+
* The store instance to use for making requests. If contexts are available, this
|
|
399
|
+
* will be the `store` on the context, else it will be the store service.
|
|
400
|
+
*
|
|
401
|
+
* @internal
|
|
402
|
+
*/
|
|
403
|
+
get store() {
|
|
404
|
+
const store = this.args.store || this._store;
|
|
405
|
+
(test => {
|
|
406
|
+
if (!test) {
|
|
407
|
+
throw new Error(`No store was provided to the <Request> component. Either provide a store via the @store arg or by registering a store service.`);
|
|
408
|
+
}
|
|
409
|
+
})(store);
|
|
410
|
+
return store;
|
|
411
|
+
}
|
|
412
|
+
_state = null;
|
|
413
|
+
get state() {
|
|
414
|
+
let {
|
|
415
|
+
_state
|
|
416
|
+
} = this;
|
|
417
|
+
const {
|
|
418
|
+
store
|
|
419
|
+
} = this;
|
|
420
|
+
const {
|
|
421
|
+
subscription
|
|
422
|
+
} = this.args;
|
|
423
|
+
if (_state && (_state.store !== store || subscription)) {
|
|
424
|
+
_state[DISPOSE]();
|
|
425
|
+
_state = null;
|
|
426
|
+
}
|
|
427
|
+
if (subscription) {
|
|
428
|
+
return subscription;
|
|
429
|
+
}
|
|
430
|
+
if (!_state) {
|
|
431
|
+
this._state = _state = createRequestSubscription(store, this.args);
|
|
432
|
+
}
|
|
433
|
+
return _state;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The chrome component to use for rendering the request.
|
|
437
|
+
*
|
|
438
|
+
* @private
|
|
439
|
+
*/
|
|
440
|
+
get Chrome() {
|
|
441
|
+
return this.args.chrome || DefaultChrome;
|
|
442
|
+
}
|
|
443
|
+
static {
|
|
444
|
+
decorateMethodV2(this.prototype, "Chrome", [memoized]);
|
|
445
|
+
}
|
|
446
|
+
willDestroy() {
|
|
447
|
+
if (this._state) {
|
|
448
|
+
this._state[DISPOSE]();
|
|
449
|
+
this._state = null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
static {
|
|
453
|
+
setComponentTemplate(precompileTemplate("\n <this.Chrome @state={{if this.state.isIdle null this.state.reqState}} @features={{this.state.contentFeatures}}>\n {{#if (and this.state.isIdle (has-block \"idle\"))}}\n {{yield to=\"idle\"}}\n\n {{else if this.state.isIdle}}\n <Throw @error={{IdleBlockMissingError}} />\n\n {{else if this.state.reqState.isLoading}}\n {{yield this.state.reqState.loadingState to=\"loading\"}}\n\n {{else if (and this.state.reqState.isCancelled (has-block \"cancelled\"))}}\n {{yield (notNull this.state.reqState.reason) this.state.errorFeatures to=\"cancelled\"}}\n\n {{else if (and this.state.reqState.isError (has-block \"error\"))}}\n {{yield (notNull this.state.reqState.reason) this.state.errorFeatures to=\"error\"}}\n\n {{else if this.state.reqState.isSuccess}}\n {{yield this.state.result this.state.contentFeatures to=\"content\"}}\n\n {{else if (not this.state.reqState.isCancelled)}}\n <Throw @error={{(notNull this.state.reqState.reason)}} />\n {{/if}}\n\n {{yield this.state.reqState to=\"always\"}}\n </this.Chrome>\n ", {
|
|
454
|
+
strictMode: true,
|
|
455
|
+
scope: () => ({
|
|
456
|
+
and,
|
|
457
|
+
Throw,
|
|
458
|
+
IdleBlockMissingError,
|
|
459
|
+
notNull,
|
|
460
|
+
not
|
|
461
|
+
})
|
|
462
|
+
}), this);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export { Await, Request, Throw };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { tagForProperty } from '@ember/-internals/metal';
|
|
2
|
+
import { _backburner } from '@ember/runloop';
|
|
3
|
+
import { createCache, track, updateTag, consumeTag, dirtyTag, getValue } from '@glimmer/validator';
|
|
4
|
+
import { setupSignals } from '@warp-drive/core/configure';
|
|
5
|
+
import * as _importSync20 from '@ember/test-waiters';
|
|
6
|
+
|
|
7
|
+
function esCompat(m) {
|
|
8
|
+
return m?.__esModule ? m : {
|
|
9
|
+
default: m,
|
|
10
|
+
...m
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const emberDirtyTag = dirtyTag;
|
|
15
|
+
function buildSignalConfig(options) {
|
|
16
|
+
const ARRAY_SIGNAL = options.wellknown.Array;
|
|
17
|
+
return {
|
|
18
|
+
createSignal(obj, key) {
|
|
19
|
+
{
|
|
20
|
+
if (key === ARRAY_SIGNAL) {
|
|
21
|
+
return [tagForProperty(obj, key), tagForProperty(obj, 'length'), tagForProperty(obj, '[]')];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return tagForProperty(obj, key);
|
|
25
|
+
},
|
|
26
|
+
consumeSignal(signal) {
|
|
27
|
+
{
|
|
28
|
+
if (Array.isArray(signal)) {
|
|
29
|
+
consumeTag(signal[0]);
|
|
30
|
+
consumeTag(signal[1]);
|
|
31
|
+
consumeTag(signal[2]);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
consumeTag(signal);
|
|
36
|
+
},
|
|
37
|
+
notifySignal(signal) {
|
|
38
|
+
{
|
|
39
|
+
if (Array.isArray(signal)) {
|
|
40
|
+
emberDirtyTag(signal[0]);
|
|
41
|
+
emberDirtyTag(signal[1]);
|
|
42
|
+
emberDirtyTag(signal[2]);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
emberDirtyTag(signal);
|
|
47
|
+
},
|
|
48
|
+
createMemo: (object, key, fn) => {
|
|
49
|
+
{
|
|
50
|
+
const propertyTag = tagForProperty(object, key);
|
|
51
|
+
const memo = createCache(fn);
|
|
52
|
+
let ret;
|
|
53
|
+
const wrappedFn = () => {
|
|
54
|
+
ret = getValue(memo);
|
|
55
|
+
};
|
|
56
|
+
return () => {
|
|
57
|
+
const tag = track(wrappedFn);
|
|
58
|
+
updateTag(propertyTag, tag);
|
|
59
|
+
consumeTag(tag);
|
|
60
|
+
return ret;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
willSyncFlushWatchers: () => {
|
|
65
|
+
//@ts-expect-error
|
|
66
|
+
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
67
|
+
},
|
|
68
|
+
waitFor: async promise => {
|
|
69
|
+
{
|
|
70
|
+
const {
|
|
71
|
+
waitForPromise
|
|
72
|
+
} = esCompat(_importSync20);
|
|
73
|
+
return waitForPromise(promise);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
setupSignals(buildSignalConfig);
|
|
79
|
+
|
|
80
|
+
export { buildSignalConfig };
|