@warp-drive/ember 5.7.0-alpha.23 → 5.7.0-alpha.25
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/declarations/-private/request.d.ts +31 -80
- package/declarations/index.d.ts +2 -2
- package/dist/index.js +43 -15
- package/package.json +4 -4
|
@@ -1,88 +1,27 @@
|
|
|
1
1
|
import Component from "@glimmer/component";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { RequestLoadingState, RequestState, RequestSubscription } from "@warp-drive/core/store/-private";
|
|
2
|
+
import type { ComponentLike } from "@glint/template";
|
|
3
|
+
import type { RequestManager, Store } from "@warp-drive/core";
|
|
4
|
+
import type { ContentFeatures, RecoveryFeatures, RequestArgs, RequestLoadingState, RequestState, RequestSubscription } from "@warp-drive/core/store/-private";
|
|
5
5
|
import type { StructuredErrorDocument } from "@warp-drive/core/types/request";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isHidden: boolean;
|
|
20
|
-
isRefreshing: boolean;
|
|
21
|
-
refresh: () => Promise<void>;
|
|
22
|
-
reload: () => Promise<void>;
|
|
23
|
-
abort?: () => void;
|
|
24
|
-
latestRequest?: Future<RT>;
|
|
6
|
+
export interface EmberRequestArgs<
|
|
7
|
+
RT,
|
|
8
|
+
E
|
|
9
|
+
> extends RequestArgs<RT, E> {
|
|
10
|
+
chrome?: ComponentLike<{
|
|
11
|
+
Blocks: {
|
|
12
|
+
default: [];
|
|
13
|
+
};
|
|
14
|
+
Args: {
|
|
15
|
+
state: RequestState | null;
|
|
16
|
+
features: ContentFeatures<RT>;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
25
19
|
}
|
|
26
20
|
interface RequestSignature<
|
|
27
21
|
RT,
|
|
28
22
|
E
|
|
29
23
|
> {
|
|
30
|
-
Args:
|
|
31
|
-
/**
|
|
32
|
-
* The request to monitor. This should be a `Future` instance returned
|
|
33
|
-
* by either the `store.request` or `store.requestManager.request` methods.
|
|
34
|
-
*
|
|
35
|
-
*/ request?: Future<RT>;
|
|
36
|
-
/**
|
|
37
|
-
* A query to use for the request. This should be an object that can be
|
|
38
|
-
* passed to `store.request`. Use this in place of `@request` if you would
|
|
39
|
-
* like the component to also initiate the request.
|
|
40
|
-
*
|
|
41
|
-
*/ query?: StoreRequestInput<RT>;
|
|
42
|
-
/**
|
|
43
|
-
* The store instance to use for making requests. If contexts are available,
|
|
44
|
-
* the component will default to using the `store` on the context.
|
|
45
|
-
*
|
|
46
|
-
* This is required if the store is not available via context or should be
|
|
47
|
-
* different from the store provided via context.
|
|
48
|
-
*
|
|
49
|
-
*/ store?: Store;
|
|
50
|
-
/**
|
|
51
|
-
* The autorefresh behavior for the request. This can be a boolean, or any
|
|
52
|
-
* combination of the following values: `'online'`, `'interval'`, `'invalid'`.
|
|
53
|
-
*
|
|
54
|
-
* - `'online'`: Refresh the request when the browser comes back online
|
|
55
|
-
* - `'interval'`: Refresh the request at a specified interval
|
|
56
|
-
* - `'invalid'`: Refresh the request when the store emits an invalidation
|
|
57
|
-
*
|
|
58
|
-
* If `true`, this is equivalent to `'online,invalid'`.
|
|
59
|
-
*
|
|
60
|
-
* Defaults to `false`.
|
|
61
|
-
*
|
|
62
|
-
*/ autorefresh?: AutorefreshBehaviorCombos;
|
|
63
|
-
/**
|
|
64
|
-
* The number of milliseconds to wait before refreshing the request when the
|
|
65
|
-
* browser comes back online or the network becomes available.
|
|
66
|
-
*
|
|
67
|
-
* This also controls the interval at which the request will be refreshed if
|
|
68
|
-
* the `interval` autorefresh type is enabled.
|
|
69
|
-
*
|
|
70
|
-
* Defaults to `30_000` (30 seconds).
|
|
71
|
-
*
|
|
72
|
-
*/ autorefreshThreshold?: number;
|
|
73
|
-
/**
|
|
74
|
-
* The behavior of the request initiated by autorefresh. This can be one of
|
|
75
|
-
* the following values:
|
|
76
|
-
*
|
|
77
|
-
* - `'refresh'`: Refresh the request in the background
|
|
78
|
-
* - `'reload'`: Force a reload of the request
|
|
79
|
-
* - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to
|
|
80
|
-
* reload, refresh, or do nothing.
|
|
81
|
-
*
|
|
82
|
-
* Defaults to `'policy'`.
|
|
83
|
-
*
|
|
84
|
-
*/ autorefreshBehavior?: "refresh" | "reload" | "policy";
|
|
85
|
-
};
|
|
24
|
+
Args: EmberRequestArgs<RT, E>;
|
|
86
25
|
Blocks: {
|
|
87
26
|
/**
|
|
88
27
|
* The block to render when the component is idle and waiting to be given a request.
|
|
@@ -324,7 +263,6 @@ interface RequestSignature<
|
|
|
324
263
|
* same, only one actual request will be made.
|
|
325
264
|
*
|
|
326
265
|
*
|
|
327
|
-
* @class <Request />
|
|
328
266
|
* @public
|
|
329
267
|
*/ export declare class Request<
|
|
330
268
|
RT,
|
|
@@ -336,9 +274,22 @@ interface RequestSignature<
|
|
|
336
274
|
*
|
|
337
275
|
* @internal
|
|
338
276
|
*/ _store: Store;
|
|
339
|
-
get store(): Store;
|
|
277
|
+
get store(): Store | RequestManager;
|
|
340
278
|
_state: RequestSubscription<RT, E> | null;
|
|
341
279
|
get state(): RequestSubscription<RT, E>;
|
|
280
|
+
/**
|
|
281
|
+
* The chrome component to use for rendering the request.
|
|
282
|
+
*
|
|
283
|
+
* @private
|
|
284
|
+
*/ get Chrome(): ComponentLike<{
|
|
285
|
+
Blocks: {
|
|
286
|
+
default: [];
|
|
287
|
+
};
|
|
288
|
+
Args: {
|
|
289
|
+
state: RequestState | null;
|
|
290
|
+
features: ContentFeatures<RT>;
|
|
291
|
+
};
|
|
292
|
+
}>;
|
|
342
293
|
willDestroy(): void;
|
|
343
294
|
}
|
|
344
295
|
export {};
|
package/declarations/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*
|
|
44
44
|
* @module
|
|
45
45
|
*/
|
|
46
|
-
export { Request } from "./-private/request.js";
|
|
46
|
+
export { Request, type ContentFeatures } from "./-private/request.js";
|
|
47
47
|
export { Await, Throw } from "./-private/await.js";
|
|
48
48
|
/**
|
|
49
49
|
* PromiseState provides a reactive wrapper for a promise which allows you write declarative
|
|
@@ -212,4 +212,4 @@ export { getPromiseState } from "@warp-drive/core/store/-private";
|
|
|
212
212
|
* @param future
|
|
213
213
|
* @return {RequestState}
|
|
214
214
|
*/
|
|
215
|
-
export { getRequestState, type RequestLoadingState } from "@warp-drive/core/store/-private";
|
|
215
|
+
export { getRequestState, createRequestSubscription, type RequestLoadingState } from "@warp-drive/core/store/-private";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { service } from '@ember/service';
|
|
2
2
|
import Component from '@glimmer/component';
|
|
3
|
+
import { cached } from '@glimmer/tracking';
|
|
3
4
|
import { macroCondition, moduleExists, importSync, getGlobalConfig } from '@embroider/macros';
|
|
4
5
|
import { getPromiseState, DISPOSE, createRequestSubscription } from '@warp-drive/core/store/-private';
|
|
5
|
-
export { getPromiseState, getRequestState } from '@warp-drive/core/store/-private';
|
|
6
|
+
export { createRequestSubscription, getPromiseState, getRequestState } from '@warp-drive/core/store/-private';
|
|
6
7
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
7
8
|
import { setComponentTemplate } from '@ember/component';
|
|
9
|
+
import templateOnly from '@ember/component/template-only';
|
|
8
10
|
|
|
9
11
|
const and = (x, y) => Boolean(x && y);
|
|
10
12
|
/**
|
|
@@ -129,6 +131,20 @@ function decorateFieldV2(prototype, prop, decorators, initializer) {
|
|
|
129
131
|
deferDecorator(prototype, prop, desc);
|
|
130
132
|
}
|
|
131
133
|
}
|
|
134
|
+
function decorateMethodV2(prototype, prop, decorators) {
|
|
135
|
+
const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
|
|
136
|
+
let desc = {
|
|
137
|
+
...origDesc
|
|
138
|
+
};
|
|
139
|
+
for (let decorator of decorators) {
|
|
140
|
+
desc = decorator(prototype, prop, desc) || desc;
|
|
141
|
+
}
|
|
142
|
+
if (desc.initializer !== void 0) {
|
|
143
|
+
desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
|
|
144
|
+
desc.initializer = void 0;
|
|
145
|
+
}
|
|
146
|
+
Object.defineProperty(prototype, prop, desc);
|
|
147
|
+
}
|
|
132
148
|
function initializeDeferredDecorator(target, prop) {
|
|
133
149
|
let desc = findDeferredDecorator(target.constructor, prop);
|
|
134
150
|
if (desc) {
|
|
@@ -158,15 +174,9 @@ if (macroCondition(moduleExists('ember-provide-consume-context'))) {
|
|
|
158
174
|
} = importSync('ember-provide-consume-context');
|
|
159
175
|
consume = contextConsume;
|
|
160
176
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Utilities for keeping the request fresh
|
|
168
|
-
*/
|
|
169
|
-
|
|
177
|
+
const DefaultChrome = setComponentTemplate(precompileTemplate("{{yield}}", {
|
|
178
|
+
strictMode: true
|
|
179
|
+
}), templateOnly());
|
|
170
180
|
/**
|
|
171
181
|
* The `<Request />` component is a powerful tool for managing data fetching and
|
|
172
182
|
* state in your Ember application. It provides a declarative approach to reactive
|
|
@@ -381,7 +391,6 @@ if (macroCondition(moduleExists('ember-provide-consume-context'))) {
|
|
|
381
391
|
* same, only one actual request will be made.
|
|
382
392
|
*
|
|
383
393
|
*
|
|
384
|
-
* @class <Request />
|
|
385
394
|
* @public
|
|
386
395
|
*/
|
|
387
396
|
class Request extends Component {
|
|
@@ -412,21 +421,40 @@ class Request extends Component {
|
|
|
412
421
|
const {
|
|
413
422
|
store
|
|
414
423
|
} = this;
|
|
415
|
-
|
|
424
|
+
const {
|
|
425
|
+
subscription
|
|
426
|
+
} = this.args;
|
|
427
|
+
if (_state && (_state.store !== store || subscription)) {
|
|
416
428
|
_state[DISPOSE]();
|
|
417
429
|
_state = null;
|
|
418
430
|
}
|
|
431
|
+
if (subscription) {
|
|
432
|
+
return subscription;
|
|
433
|
+
}
|
|
419
434
|
if (!_state) {
|
|
420
435
|
this._state = _state = createRequestSubscription(store, this.args);
|
|
421
436
|
}
|
|
422
437
|
return _state;
|
|
423
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* The chrome component to use for rendering the request.
|
|
441
|
+
*
|
|
442
|
+
* @private
|
|
443
|
+
*/
|
|
444
|
+
get Chrome() {
|
|
445
|
+
return this.args.chrome || DefaultChrome;
|
|
446
|
+
}
|
|
447
|
+
static {
|
|
448
|
+
decorateMethodV2(this.prototype, "Chrome", [cached]);
|
|
449
|
+
}
|
|
424
450
|
willDestroy() {
|
|
425
|
-
this._state
|
|
426
|
-
|
|
451
|
+
if (this._state) {
|
|
452
|
+
this._state[DISPOSE]();
|
|
453
|
+
this._state = null;
|
|
454
|
+
}
|
|
427
455
|
}
|
|
428
456
|
static {
|
|
429
|
-
setComponentTemplate(precompileTemplate("\n {{#if (and this.state.isIdle (has-block \"idle\"))}}\n
|
|
457
|
+
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 ", {
|
|
430
458
|
strictMode: true,
|
|
431
459
|
scope: () => ({
|
|
432
460
|
and,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/ember",
|
|
3
3
|
"description": "Data bindings and utilities for Ember applications using WarpDrive",
|
|
4
|
-
"version": "5.7.0-alpha.
|
|
4
|
+
"version": "5.7.0-alpha.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@embroider/macros": "^1.16.12",
|
|
41
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
41
|
+
"@warp-drive/core": "5.7.0-alpha.25"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
44
|
"ember-provide-consume-context": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@embroider/addon-dev": "^7.1.3",
|
|
61
61
|
"@ember/test-helpers": "5.2.0",
|
|
62
62
|
"@ember/test-waiters": "^4.1.0",
|
|
63
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
64
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
63
|
+
"@warp-drive/internal-config": "5.7.0-alpha.25",
|
|
64
|
+
"@warp-drive/core": "5.7.0-alpha.25",
|
|
65
65
|
"babel-plugin-ember-template-compilation": "^2.4.1",
|
|
66
66
|
"ember-template-imports": "^4.3.0",
|
|
67
67
|
"ember-source": "~6.3.0",
|