@warp-drive/ember 5.4.0-alpha.149 → 5.4.0-alpha.151
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/dist/index.js +455 -6
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/unstable-preview-types/-private/await.d.ts +51 -0
- package/unstable-preview-types/-private/await.d.ts.map +1 -1
- package/unstable-preview-types/-private/promise-state.d.ts +78 -0
- package/unstable-preview-types/-private/promise-state.d.ts.map +1 -1
- package/unstable-preview-types/-private/request-state.d.ts +94 -0
- package/unstable-preview-types/-private/request-state.d.ts.map +1 -1
- package/unstable-preview-types/-private/request.d.ts +304 -5
- package/unstable-preview-types/-private/request.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +19 -0
- package/unstable-preview-types/index.d.ts.map +1 -1
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
declare module '@warp-drive/ember/-private/request-state' {
|
|
2
2
|
import type { Future, ImmutableRequestInfo, ResponseInfo, StructuredErrorDocument } from '@ember-data/request';
|
|
3
|
+
/**
|
|
4
|
+
* Lazily consumes the stream of a request, providing a number of
|
|
5
|
+
* reactive properties that can be used to build UIs that respond
|
|
6
|
+
* to the progress of a request.
|
|
7
|
+
*
|
|
8
|
+
* @class RequestLoadingState
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
3
11
|
export class RequestLoadingState {
|
|
4
12
|
_stream: TransformStream | null;
|
|
5
13
|
_future: Future<unknown>;
|
|
@@ -37,6 +45,34 @@ declare module '@warp-drive/ember/-private/request-state' {
|
|
|
37
45
|
constructor(future: Future<unknown>);
|
|
38
46
|
abort: () => void;
|
|
39
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* RequestState extends the concept of PromiseState to provide a reactive
|
|
50
|
+
* wrapper for a request `Future` which allows you write declarative code
|
|
51
|
+
* around a Future's control flow.
|
|
52
|
+
*
|
|
53
|
+
* It is useful in both Template and JavaScript contexts, allowing you
|
|
54
|
+
* to quickly derive behaviors and data from pending, error and success
|
|
55
|
+
* states.
|
|
56
|
+
*
|
|
57
|
+
* The key difference between a Promise and a Future is that Futures provide
|
|
58
|
+
* access to a stream of their content, the identity of the request (if any)
|
|
59
|
+
* as well as the ability to attempt to abort the request.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* interface Future<T> extends Promise<T>> {
|
|
63
|
+
* getStream(): Promise<ReadableStream>;
|
|
64
|
+
* abort(): void;
|
|
65
|
+
* lid: StableDocumentIdentifier | null;
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* These additional APIs allow us to craft even richer state experiences.
|
|
70
|
+
*
|
|
71
|
+
* To get the state of a request, use `getRequestState`.
|
|
72
|
+
*
|
|
73
|
+
* @class RequestState
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
40
76
|
export class RequestState<T = unknown, RT = unknown> {
|
|
41
77
|
#private;
|
|
42
78
|
result: RT | null;
|
|
@@ -50,6 +86,64 @@ declare module '@warp-drive/ember/-private/request-state' {
|
|
|
50
86
|
get loadingState(): RequestLoadingState;
|
|
51
87
|
constructor(future: Future<RT>);
|
|
52
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
*
|
|
92
|
+
* `getRequestState` can be used in both JavaScript and Template contexts.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { getRequestState } from '@warp-drive/ember';
|
|
96
|
+
*
|
|
97
|
+
* const state = getRequestState(future);
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* For instance, we could write a getter on a component that updates whenever
|
|
101
|
+
* the request state advances or the future changes, by combining the function
|
|
102
|
+
* with the use of `@cached`
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* class Component {
|
|
106
|
+
* @cached
|
|
107
|
+
* get title() {
|
|
108
|
+
* const state = getRequestState(this.args.request);
|
|
109
|
+
* if (state.isPending) {
|
|
110
|
+
* return 'loading...';
|
|
111
|
+
* }
|
|
112
|
+
* if (state.isError) { return null; }
|
|
113
|
+
* return state.result.title;
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* Or in a template as a helper:
|
|
119
|
+
*
|
|
120
|
+
* ```gjs
|
|
121
|
+
* import { getRequestState } from '@warp-drive/ember';
|
|
122
|
+
*
|
|
123
|
+
* <template>
|
|
124
|
+
* {{#let (getRequestState @request) as |state|}}
|
|
125
|
+
* {{#if state.isPending}}
|
|
126
|
+
* <Spinner />
|
|
127
|
+
* {{else if state.isError}}
|
|
128
|
+
* <ErrorForm @error={{state.error}} />
|
|
129
|
+
* {{else}}
|
|
130
|
+
* <h1>{{state.result.title}}</h1>
|
|
131
|
+
* {{/if}}
|
|
132
|
+
* {{/let}}
|
|
133
|
+
* </template>
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* If looking to use in a template, consider also the `<Request />` component
|
|
137
|
+
* which offers a numbe of additional capabilities for requests *beyond* what
|
|
138
|
+
* `RequestState` provides.
|
|
139
|
+
*
|
|
140
|
+
* @method getRequestState
|
|
141
|
+
* @for @warp-drive/ember
|
|
142
|
+
* @static
|
|
143
|
+
* @public
|
|
144
|
+
* @param future
|
|
145
|
+
* @return {RequestState}
|
|
146
|
+
*/
|
|
53
147
|
export function getRequestState<RT, T>(future: Future<RT>): RequestState<T, RT>;
|
|
54
148
|
}
|
|
55
149
|
//# sourceMappingURL=request-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../../src/-private/request-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../../src/-private/request-state.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,YAAY,EAEZ,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAiE7B;;;;;;;GAOG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AO,EAAE,EAAE,GAAG,OAAO;;IAIxC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAQ;IACzB,KAAK,EAAE,uBAAuB,GAAG,IAAI,CAAQ;IAC7C,SAAS,UAAQ;IACjB,SAAS,UAAS;IAClB,OAAO,UAAS;IAChB,OAAO,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAQ;IACnD,QAAQ,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI,CAAQ;IAEzD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,YAAY,wBAMf;gBAEW,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CAqC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAS9E"}
|
|
@@ -5,7 +5,7 @@ declare module '@warp-drive/ember/-private/request' {
|
|
|
5
5
|
import type Store from '@ember-data/store';
|
|
6
6
|
import type { RequestLoadingState, RequestState } from '@warp-drive/ember/-private/request-state.ts';
|
|
7
7
|
type AutorefreshBehaviorType = 'online' | 'interval' | 'invalid';
|
|
8
|
-
type AutorefreshBehaviorCombos =
|
|
8
|
+
type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
|
|
9
9
|
type ContentFeatures<RT> = {
|
|
10
10
|
isOnline: boolean;
|
|
11
11
|
isHidden: boolean;
|
|
@@ -17,16 +17,91 @@ declare module '@warp-drive/ember/-private/request' {
|
|
|
17
17
|
};
|
|
18
18
|
interface RequestSignature<T, RT> {
|
|
19
19
|
Args: {
|
|
20
|
+
/**
|
|
21
|
+
* The request to monitor. This should be a `Future` instance returned
|
|
22
|
+
* by either the `store.request` or `store.requestManager.request` methods.
|
|
23
|
+
*
|
|
24
|
+
* @typedoc
|
|
25
|
+
*/
|
|
20
26
|
request?: Future<RT>;
|
|
27
|
+
/**
|
|
28
|
+
* A query to use for the request. This should be an object that can be
|
|
29
|
+
* passed to `store.request`. Use this in place of `@request` if you would
|
|
30
|
+
* like the component to also initiate the request.
|
|
31
|
+
*
|
|
32
|
+
* @typedoc
|
|
33
|
+
*/
|
|
21
34
|
query?: StoreRequestInput<T, RT>;
|
|
35
|
+
/**
|
|
36
|
+
* The store instance to use for making requests. If contexts are available,
|
|
37
|
+
* the component will default to using the `store` on the context.
|
|
38
|
+
*
|
|
39
|
+
* This is required if the store is not available via context or should be
|
|
40
|
+
* different from the store provided via context.
|
|
41
|
+
*
|
|
42
|
+
* @typedoc
|
|
43
|
+
*/
|
|
22
44
|
store?: Store;
|
|
45
|
+
/**
|
|
46
|
+
* The autorefresh behavior for the request. This can be a boolean, or any
|
|
47
|
+
* combination of the following values: `'online'`, `'interval'`, `'invalid'`.
|
|
48
|
+
*
|
|
49
|
+
* - `'online'`: Refresh the request when the browser comes back online
|
|
50
|
+
* - `'interval'`: Refresh the request at a specified interval
|
|
51
|
+
* - `'invalid'`: Refresh the request when the store emits an invalidation
|
|
52
|
+
*
|
|
53
|
+
* If `true`, this is equivalent to `'online,invalid'`.
|
|
54
|
+
*
|
|
55
|
+
* Defaults to `false`.
|
|
56
|
+
*
|
|
57
|
+
* @typedoc
|
|
58
|
+
*/
|
|
23
59
|
autorefresh?: AutorefreshBehaviorCombos;
|
|
60
|
+
/**
|
|
61
|
+
* The number of milliseconds to wait before refreshing the request when the
|
|
62
|
+
* browser comes back online or the network becomes available.
|
|
63
|
+
*
|
|
64
|
+
* This also controls the interval at which the request will be refreshed if
|
|
65
|
+
* the `interval` autorefresh type is enabled.
|
|
66
|
+
*
|
|
67
|
+
* Defaults to `30_000` (30 seconds).
|
|
68
|
+
*
|
|
69
|
+
* @typedoc
|
|
70
|
+
*/
|
|
24
71
|
autorefreshThreshold?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The behavior of the request initiated by autorefresh. This can be one of
|
|
74
|
+
* the following values:
|
|
75
|
+
*
|
|
76
|
+
* - `'refresh'`: Refresh the request in the background
|
|
77
|
+
* - `'reload'`: Force a reload of the request
|
|
78
|
+
* - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to
|
|
79
|
+
* reload, refresh, or do nothing.
|
|
80
|
+
*
|
|
81
|
+
* Defaults to `'policy'`.
|
|
82
|
+
*
|
|
83
|
+
* @typedoc
|
|
84
|
+
*/
|
|
25
85
|
autorefreshBehavior?: 'refresh' | 'reload' | 'policy';
|
|
26
86
|
};
|
|
27
87
|
Blocks: {
|
|
88
|
+
/**
|
|
89
|
+
* The block to render when the component is idle and waiting to be given a request.
|
|
90
|
+
*
|
|
91
|
+
* @typedoc
|
|
92
|
+
*/
|
|
28
93
|
idle: [];
|
|
94
|
+
/**
|
|
95
|
+
* The block to render when the request is loading.
|
|
96
|
+
*
|
|
97
|
+
* @typedoc
|
|
98
|
+
*/
|
|
29
99
|
loading: [state: RequestLoadingState];
|
|
100
|
+
/**
|
|
101
|
+
* The block to render when the request was cancelled.
|
|
102
|
+
*
|
|
103
|
+
* @typedoc
|
|
104
|
+
*/
|
|
30
105
|
cancelled: [
|
|
31
106
|
error: StructuredErrorDocument,
|
|
32
107
|
features: {
|
|
@@ -35,6 +110,15 @@ declare module '@warp-drive/ember/-private/request' {
|
|
|
35
110
|
retry: () => Promise<void>;
|
|
36
111
|
}
|
|
37
112
|
];
|
|
113
|
+
/**
|
|
114
|
+
* The block to render when the request failed. If this block is not provided,
|
|
115
|
+
* the error will be rethrown.
|
|
116
|
+
*
|
|
117
|
+
* Thus it is required to provide an error block and proper error handling if
|
|
118
|
+
* you do not want the error to crash the application.
|
|
119
|
+
*
|
|
120
|
+
* @typedoc
|
|
121
|
+
*/
|
|
38
122
|
error: [
|
|
39
123
|
error: StructuredErrorDocument,
|
|
40
124
|
features: {
|
|
@@ -43,16 +127,231 @@ declare module '@warp-drive/ember/-private/request' {
|
|
|
43
127
|
retry: () => Promise<void>;
|
|
44
128
|
}
|
|
45
129
|
];
|
|
130
|
+
/**
|
|
131
|
+
* The block to render when the request succeeded.
|
|
132
|
+
*
|
|
133
|
+
* @typedoc
|
|
134
|
+
*/
|
|
46
135
|
content: [value: RT, features: ContentFeatures<RT>];
|
|
47
136
|
always: [state: RequestState<T, RT>];
|
|
48
137
|
};
|
|
49
138
|
}
|
|
50
139
|
/**
|
|
51
|
-
* The `<Request
|
|
52
|
-
* state in your Ember application. It provides declarative reactive
|
|
53
|
-
* for managing requests and state in your application.
|
|
140
|
+
* The `<Request />` component is a powerful tool for managing data fetching and
|
|
141
|
+
* state in your Ember application. It provides a declarative approach to reactive
|
|
142
|
+
* control-flow for managing requests and state in your application.
|
|
54
143
|
*
|
|
55
|
-
*
|
|
144
|
+
* The `<Request />` component is ideal for handling "boundaries", outside which some
|
|
145
|
+
* state is still allowed to be unresolved and within which it MUST be resolved.
|
|
146
|
+
*
|
|
147
|
+
* ## Request States
|
|
148
|
+
*
|
|
149
|
+
* `<Request />` has five states, only one of which will be active and rendered at a time.
|
|
150
|
+
*
|
|
151
|
+
* - `idle`: The component is waiting to be given a request to monitor
|
|
152
|
+
* - `loading`: The request is in progress
|
|
153
|
+
* - `error`: The request failed
|
|
154
|
+
* - `content`: The request succeeded
|
|
155
|
+
* - `cancelled`: The request was cancelled
|
|
156
|
+
*
|
|
157
|
+
* Additionally, the `content` state has a `refresh` method that can be used to
|
|
158
|
+
* refresh the request in the background, which is available as a sub-state of
|
|
159
|
+
* the `content` state.
|
|
160
|
+
*
|
|
161
|
+
* As with the `<Await />` component, if no error block is provided and the request
|
|
162
|
+
* rejects, the error will be thrown. Cancellation errors are swallowed instead of
|
|
163
|
+
* rethrown if no error block or cancellation block is present.
|
|
164
|
+
*
|
|
165
|
+
* ```gts
|
|
166
|
+
* import { Request } from '@warp-drive/ember';
|
|
167
|
+
*
|
|
168
|
+
* <template>
|
|
169
|
+
* <Request @request={{@request}}>
|
|
170
|
+
* <:loading as |state|>
|
|
171
|
+
* <Spinner @percentDone={{state.completedRatio}} />
|
|
172
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
173
|
+
* </:loading>
|
|
174
|
+
*
|
|
175
|
+
* <:error as |error state|>
|
|
176
|
+
* <ErrorForm @error={{error}} />
|
|
177
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
178
|
+
* </:error>
|
|
179
|
+
*
|
|
180
|
+
* <:content as |data state|>
|
|
181
|
+
* <h1>{{data.title}}</h1>
|
|
182
|
+
* {{#if state.isBackgroundReloading}}
|
|
183
|
+
* <SmallSpinner />
|
|
184
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
185
|
+
* {{else}}
|
|
186
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
187
|
+
* {{/if}}
|
|
188
|
+
* </:content>
|
|
189
|
+
*
|
|
190
|
+
* <:cancelled as |error state|>
|
|
191
|
+
* <h2>The Request was cancelled</h2>
|
|
192
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
193
|
+
* </:cancelled>
|
|
194
|
+
*
|
|
195
|
+
* <:idle>
|
|
196
|
+
* <button {{on "click" @kickOffRequest}}>Load Preview?</button>
|
|
197
|
+
* </:idle>
|
|
198
|
+
*
|
|
199
|
+
* </Request>
|
|
200
|
+
* </template>
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* ## Streaming Data
|
|
204
|
+
*
|
|
205
|
+
* The loading state exposes the download `ReadableStream` instance for consumption
|
|
206
|
+
*
|
|
207
|
+
* ```gjs
|
|
208
|
+
* import { Request } from '@warp-drive/ember';
|
|
209
|
+
*
|
|
210
|
+
* <template>
|
|
211
|
+
* <Request @request={{@request}}>
|
|
212
|
+
* <:loading as |state|>
|
|
213
|
+
* <Video @stream={{state.stream}} />
|
|
214
|
+
* </:loading>
|
|
215
|
+
*
|
|
216
|
+
* <:error as |error|>
|
|
217
|
+
* <ErrorForm @error={{error}} />
|
|
218
|
+
* </:error>
|
|
219
|
+
* </Request>
|
|
220
|
+
* </template>
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* ## Retry
|
|
224
|
+
*
|
|
225
|
+
* Cancelled and error'd requests may be retried by calling the `retry` method.
|
|
226
|
+
*
|
|
227
|
+
* Retry will restart the state progression, using the loading, error, cancelled,
|
|
228
|
+
* and content blocks as appropriate.
|
|
229
|
+
*
|
|
230
|
+
* ## Reloading
|
|
231
|
+
*
|
|
232
|
+
* The `reload` method will force the request to be fully re-executed, bypassing
|
|
233
|
+
* cache and restarting the state progression through the loading, error, and
|
|
234
|
+
* content blocks as appropriate.
|
|
235
|
+
*
|
|
236
|
+
* Background reload (refresh) is a special substate of the content state that
|
|
237
|
+
* allows you to refresh the request in the background. This is useful for when
|
|
238
|
+
* you want to update the data in the background without blocking the UI.
|
|
239
|
+
*
|
|
240
|
+
* Reload and refresh are available as methods on the `content` state.
|
|
241
|
+
*
|
|
242
|
+
* ```gjs
|
|
243
|
+
* import { Request } from '@warp-drive/ember';
|
|
244
|
+
*
|
|
245
|
+
* <template>
|
|
246
|
+
* <Request @request={{@request}}>
|
|
247
|
+
* <:content as |data state|>
|
|
248
|
+
* <h1>{{data.title}}</h1>
|
|
249
|
+
* {{#if state.isBackgroundReloading}}
|
|
250
|
+
* <SmallSpinner />
|
|
251
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
252
|
+
* {{/if}}
|
|
253
|
+
*
|
|
254
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
255
|
+
* <button {{on "click" state.reload}}>Reload</button>
|
|
256
|
+
* </:content>
|
|
257
|
+
* </Request>
|
|
258
|
+
* </template>
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* ## Advanced Reloading
|
|
262
|
+
*
|
|
263
|
+
* We can nest our usage of `<Request />` to handle more advanced
|
|
264
|
+
* reloading scenarios.
|
|
265
|
+
*
|
|
266
|
+
* ```gjs
|
|
267
|
+
* import { Request } from '@warp-drive/ember';
|
|
268
|
+
*
|
|
269
|
+
* <template>
|
|
270
|
+
* <Request @request={{@request}}>
|
|
271
|
+
* <:cancelled>
|
|
272
|
+
* <h2>The Request Cancelled</h2>
|
|
273
|
+
* </:cancelled>
|
|
274
|
+
*
|
|
275
|
+
* <:error as |error|>
|
|
276
|
+
* <ErrorForm @error={{error}} />
|
|
277
|
+
* </:error>
|
|
278
|
+
*
|
|
279
|
+
* <:content as |result state|>
|
|
280
|
+
* <Request @request={{state.latestRequest}}>
|
|
281
|
+
* <!-- Handle Background Request -->
|
|
282
|
+
* </Request>
|
|
283
|
+
*
|
|
284
|
+
* <h1>{{result.title}}</h1>
|
|
285
|
+
*
|
|
286
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
287
|
+
* </:content>
|
|
288
|
+
* </Request>
|
|
289
|
+
* </template>
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* ## Autorefresh
|
|
293
|
+
*
|
|
294
|
+
* `<Request />` supports automatic refresh and reload under certain conditions.
|
|
295
|
+
*
|
|
296
|
+
* - `online`: This occurs when a browser window or tab comes back to the foreground
|
|
297
|
+
* after being backgrounded or when the network reports as being online after
|
|
298
|
+
* having been offline.
|
|
299
|
+
* - `interval`: This occurs when a specified amount of time has passed.
|
|
300
|
+
* - `invalid`: This occurs when the store emits a notification that the request
|
|
301
|
+
* has become invalid.
|
|
302
|
+
*
|
|
303
|
+
* You can specify when autorefresh should occur by setting the `autorefresh` arg
|
|
304
|
+
* to `true` or a comma-separated list of the above values.
|
|
305
|
+
*
|
|
306
|
+
* A value of `true` is equivalent to `'online,invalid'`.
|
|
307
|
+
*
|
|
308
|
+
* By default, an autorefresh will only occur if the browser was backgrounded or
|
|
309
|
+
* offline for more than 30s before coming back available. This amount of time can
|
|
310
|
+
* be tweaked by setting the number of milliseconds via `@autorefreshThreshold`.
|
|
311
|
+
*
|
|
312
|
+
* This arg also controls the interval at which the request will be refreshed
|
|
313
|
+
* if the `interval` autorefresh type is enabled.
|
|
314
|
+
*
|
|
315
|
+
* Finally, the behavior of the request initiated by autorefresh can be adjusted
|
|
316
|
+
* by setting the `autorefreshBehavior` arg to `'refresh'`, `'reload'`, or `'policy'`.
|
|
317
|
+
*
|
|
318
|
+
* - `'refresh'`: Refresh the request in the background
|
|
319
|
+
* - `'reload'`: Force a reload of the request
|
|
320
|
+
* - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to
|
|
321
|
+
* reload, refresh, or do nothing.
|
|
322
|
+
*
|
|
323
|
+
* More advanced refresh and reload behaviors can be created by passing the reload and
|
|
324
|
+
* refresh actions into another component. For instance, refresh could be set up on a
|
|
325
|
+
* timer or on a websocket subscription.
|
|
326
|
+
*
|
|
327
|
+
*
|
|
328
|
+
* ```gjs
|
|
329
|
+
* import { Request } from '@warp-drive/ember';
|
|
330
|
+
*
|
|
331
|
+
* <template>
|
|
332
|
+
* <Request @request={{@request}}>
|
|
333
|
+
* <:content as |result state|>
|
|
334
|
+
* <h1>{{result.title}}</h1>
|
|
335
|
+
*
|
|
336
|
+
* <Interval @period={{30_000}} @fn={{state.refresh}} />
|
|
337
|
+
* <Subscribe @channel={{@someValue}} @fn={{state.refresh}} />
|
|
338
|
+
* </:content>
|
|
339
|
+
* </Request>
|
|
340
|
+
* </template>
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* If a matching request is refreshed or reloaded by any other component,
|
|
344
|
+
* the `Request` component will react accordingly.
|
|
345
|
+
*
|
|
346
|
+
* ## Deduping
|
|
347
|
+
*
|
|
348
|
+
* The store dedupes requests by identity. If a request is made for the same identity
|
|
349
|
+
* from multiple `<Request />` components, even if the request is not referentially the
|
|
350
|
+
* same, only one actual request will be made.
|
|
351
|
+
*
|
|
352
|
+
*
|
|
353
|
+
* @class <Request />
|
|
354
|
+
* @public
|
|
56
355
|
*/
|
|
57
356
|
export class Request<T, RT> extends Component<RequestSignature<T, RT>> {
|
|
58
357
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/-private/request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/-private/request.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAK3C,OAAO,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAM3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA2B5E,KAAK,uBAAuB,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AACjE,KAAK,yBAAyB,GAC1B,OAAO,GACP,uBAAuB,GACvB,GAAG,uBAAuB,IAAI,uBAAuB,EAAE,GACvD,GAAG,uBAAuB,IAAI,uBAAuB,IAAI,uBAAuB,EAAE,CAAC;AAEvF,KAAK,eAAe,CAAC,EAAE,IAAI;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;CAC5B,CAAC;AAEF,UAAU,gBAAgB,CAAC,CAAC,EAAE,EAAE;IAC9B,IAAI,EAAE;QACJ;;;;;WAKG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAErB;;;;;;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AAK,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC;IAY3D,YAAY;IAalB,IACI,MAAM,YAIT;IAED,IACI,gBAAgB,IAAI,GAAG,CAAC,uBAAuB,CAAC,CAanD;IAUK,gBAAgB;IAqCtB,aAAa;IAOb,mBAAmB;IAqFnB,mBAAmB;IAQnB;;;;;OAKG;IACH,gBAAgB;IAgChB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IA+E3F;;;;OAIG;IACH,KAAK,sBAGH;IAEF;;;;OAIG;IACH,OAAO,sBAGL;IAEF,IACI,aAAa;;;;MAMhB;IAED,IACI,eAAe,wBAiBlB;IAED,WAAW;IAiBX,IACI,QAAQ,IAAI,MAAM,CAAC,EAAE,CAAC,CAmBzB;IAED,IACI,OAAO,IAAI,MAAM,CAAC,EAAE,CAAC,CAIxB;IAED,IAAI,KAAK,IAAI,KAAK,CASjB;IAED,IAAI,QAAQ,wBAEX;IAED,IAAI,MAAM,IACuB,EAAE,CAClC;CAuCF"}
|
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
/// <reference path="./-private/await.d.ts" />
|
|
4
4
|
/// <reference path="./-private/request.d.ts" />
|
|
5
5
|
declare module '@warp-drive/ember' {
|
|
6
|
+
/**
|
|
7
|
+
* <h3 align="center">⚛️ Data utilities for using <em style="color: lightgreen">Warp</em><strong style="color: magenta">Drive</strong> with 🐹 <em style="color: orange">Ember</em><em style="color: lightblue">.js</em></h3>
|
|
8
|
+
*
|
|
9
|
+
* ## Installation
|
|
10
|
+
*
|
|
11
|
+
* ```cli
|
|
12
|
+
* pnpm install @warp-drive/ember
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* ## About
|
|
16
|
+
*
|
|
17
|
+
* This library provides reactive utilities for working with promises
|
|
18
|
+
* and requests, building over these primitives to provide functions
|
|
19
|
+
* and components that enable you to build robust performant apps with
|
|
20
|
+
* elegant control flow.
|
|
21
|
+
*
|
|
22
|
+
* @module @warp-drive/ember
|
|
23
|
+
* @main @warp-drive/ember
|
|
24
|
+
*/
|
|
6
25
|
export { getRequestState } from '@warp-drive/ember/-private/request-state';
|
|
7
26
|
export { getPromiseState } from '@warp-drive/ember/-private/promise-state';
|
|
8
27
|
export { Request } from '@warp-drive/ember/-private/request.gts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC"}
|