@warp-drive-mirror/ember 5.8.0-alpha.30 → 5.8.0-alpha.32
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/unpkg/dev/declarations/-private/await.d.ts +81 -0
- package/dist/unpkg/dev/declarations/-private/request.d.ts +289 -0
- package/dist/unpkg/dev/declarations/index.d.ts +8 -0
- package/dist/unpkg/dev/declarations/install.d.ts +6 -0
- package/dist/unpkg/dev/index.js +476 -0
- package/dist/unpkg/dev/install.js +77 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/await.d.ts +81 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/request.d.ts +289 -0
- package/dist/unpkg/dev-deprecated/declarations/index.d.ts +8 -0
- package/dist/unpkg/dev-deprecated/declarations/install.d.ts +6 -0
- package/dist/unpkg/dev-deprecated/index.js +476 -0
- package/dist/unpkg/dev-deprecated/install.js +77 -0
- package/dist/unpkg/prod/declarations/-private/await.d.ts +81 -0
- package/dist/unpkg/prod/declarations/-private/request.d.ts +289 -0
- package/dist/unpkg/prod/declarations/index.d.ts +8 -0
- package/dist/unpkg/prod/declarations/install.d.ts +6 -0
- package/dist/unpkg/prod/index.js +476 -0
- package/dist/unpkg/prod/install.js +77 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/await.d.ts +81 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/request.d.ts +289 -0
- package/dist/unpkg/prod-deprecated/declarations/index.d.ts +8 -0
- package/dist/unpkg/prod-deprecated/declarations/install.d.ts +6 -0
- package/dist/unpkg/prod-deprecated/index.js +476 -0
- package/dist/unpkg/prod-deprecated/install.js +77 -0
- package/package.json +4 -4
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type Owner from "@ember/owner";
|
|
2
|
+
import Component from "@glimmer/component";
|
|
3
|
+
import { type PromiseState } from "@warp-drive-mirror/core/reactive";
|
|
4
|
+
import type { Awaitable } from "@warp-drive-mirror/core/request";
|
|
5
|
+
export declare const and: (x: unknown, y: unknown) => boolean;
|
|
6
|
+
interface ThrowSignature<E = Error | string | object> {
|
|
7
|
+
Args: {
|
|
8
|
+
error: E;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
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
|
+
*/ export declare class Throw<T> extends Component<ThrowSignature<T>> {
|
|
24
|
+
constructor(owner: Owner, args: ThrowSignature<T>["Args"]);
|
|
25
|
+
}
|
|
26
|
+
interface AwaitSignature<
|
|
27
|
+
T,
|
|
28
|
+
E = Error | string | object
|
|
29
|
+
> {
|
|
30
|
+
Args: {
|
|
31
|
+
promise: Promise<T> | Awaitable<T, E>;
|
|
32
|
+
};
|
|
33
|
+
Blocks: {
|
|
34
|
+
pending: [];
|
|
35
|
+
error: [error: E];
|
|
36
|
+
success: [value: T];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The `<Await />` component allow you to utilize reactive control flow
|
|
41
|
+
* for asynchronous states in your application.
|
|
42
|
+
*
|
|
43
|
+
* Await is ideal for handling "boundaries", outside which some state is
|
|
44
|
+
* still allowed to be unresolved and within which it MUST be resolved.
|
|
45
|
+
*
|
|
46
|
+
* ```gts
|
|
47
|
+
* import { Await } from '@warp-drive-mirror/ember';
|
|
48
|
+
*
|
|
49
|
+
* <template>
|
|
50
|
+
* <Await @promise={{@request}}>
|
|
51
|
+
* <:pending>
|
|
52
|
+
* <Spinner />
|
|
53
|
+
* </:pending>
|
|
54
|
+
*
|
|
55
|
+
* <:error as |error|>
|
|
56
|
+
* <ErrorForm @error={{error}} />
|
|
57
|
+
* </:error>
|
|
58
|
+
*
|
|
59
|
+
* <:success as |result|>
|
|
60
|
+
* <h1>{{result.title}}</h1>
|
|
61
|
+
* </:success>
|
|
62
|
+
* </Await>
|
|
63
|
+
* </template>
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* The `<Await />` component requires that error states are properly handled.
|
|
67
|
+
*
|
|
68
|
+
* If no error block is provided and the promise rejects, the error will
|
|
69
|
+
* be thrown.
|
|
70
|
+
*
|
|
71
|
+
* @category Components
|
|
72
|
+
* @public
|
|
73
|
+
*/ export declare class Await<
|
|
74
|
+
T,
|
|
75
|
+
E
|
|
76
|
+
> extends Component<AwaitSignature<T, E>> {
|
|
77
|
+
get state(): Readonly<PromiseState<T, E>>;
|
|
78
|
+
get error(): E;
|
|
79
|
+
get result(): T;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import Component from "@glimmer/component";
|
|
2
|
+
import type { ComponentLike } from "@glint/template";
|
|
3
|
+
import type { RequestManager, Store } from "@warp-drive-mirror/core";
|
|
4
|
+
import type { ContentFeatures, RecoveryFeatures, RequestArgs, RequestLoadingState, RequestState, RequestSubscription } from "@warp-drive-mirror/core/store/-private";
|
|
5
|
+
import type { StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
6
|
+
export { ContentFeatures, RecoveryFeatures };
|
|
7
|
+
export interface EmberRequestArgs<
|
|
8
|
+
RT,
|
|
9
|
+
E
|
|
10
|
+
> extends RequestArgs<RT, E> {
|
|
11
|
+
chrome?: ComponentLike<{
|
|
12
|
+
Blocks: {
|
|
13
|
+
default: [];
|
|
14
|
+
};
|
|
15
|
+
Args: {
|
|
16
|
+
state: RequestState | null;
|
|
17
|
+
features: ContentFeatures<RT>;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
interface RequestSignature<
|
|
22
|
+
RT,
|
|
23
|
+
E
|
|
24
|
+
> {
|
|
25
|
+
Args: EmberRequestArgs<RT, E>;
|
|
26
|
+
Blocks: {
|
|
27
|
+
/**
|
|
28
|
+
* The block to render when the component is idle and waiting to be given a request.
|
|
29
|
+
*
|
|
30
|
+
*/ idle: [];
|
|
31
|
+
/**
|
|
32
|
+
* The block to render when the request is loading.
|
|
33
|
+
*
|
|
34
|
+
*/ loading: [state: RequestLoadingState];
|
|
35
|
+
/**
|
|
36
|
+
* The block to render when the request was cancelled.
|
|
37
|
+
*
|
|
38
|
+
*/ cancelled: [error: StructuredErrorDocument<E>, features: RecoveryFeatures];
|
|
39
|
+
/**
|
|
40
|
+
* The block to render when the request failed. If this block is not provided,
|
|
41
|
+
* the error will be rethrown.
|
|
42
|
+
*
|
|
43
|
+
* Thus it is required to provide an error block and proper error handling if
|
|
44
|
+
* you do not want the error to crash the application.
|
|
45
|
+
*/ error: [error: StructuredErrorDocument<E>, features: RecoveryFeatures];
|
|
46
|
+
/**
|
|
47
|
+
* The block to render when the request succeeded.
|
|
48
|
+
*
|
|
49
|
+
*/ content: [value: RT, features: ContentFeatures<RT>];
|
|
50
|
+
always: [state: RequestState<RT, StructuredErrorDocument<E>>];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The `<Request />` component is a powerful tool for managing data fetching and
|
|
55
|
+
* state in your Ember application. It provides a declarative approach to reactive
|
|
56
|
+
* control-flow for managing requests and state in your application.
|
|
57
|
+
*
|
|
58
|
+
* The `<Request />` component is ideal for handling "boundaries", outside which some
|
|
59
|
+
* state is still allowed to be unresolved and within which it MUST be resolved.
|
|
60
|
+
*
|
|
61
|
+
* ## Request States
|
|
62
|
+
*
|
|
63
|
+
* `<Request />` has five states, only one of which will be active and rendered at a time.
|
|
64
|
+
*
|
|
65
|
+
* - `idle`: The component is waiting to be given a request to monitor
|
|
66
|
+
* - `loading`: The request is in progress
|
|
67
|
+
* - `error`: The request failed
|
|
68
|
+
* - `content`: The request succeeded
|
|
69
|
+
* - `cancelled`: The request was cancelled
|
|
70
|
+
*
|
|
71
|
+
* Additionally, the `content` state has a `refresh` method that can be used to
|
|
72
|
+
* refresh the request in the background, which is available as a sub-state of
|
|
73
|
+
* the `content` state.
|
|
74
|
+
*
|
|
75
|
+
* As with the `<Await />` component, if no error block is provided and the request
|
|
76
|
+
* rejects, the error will be thrown. Cancellation errors are swallowed instead of
|
|
77
|
+
* rethrown if no error block or cancellation block is present.
|
|
78
|
+
*
|
|
79
|
+
* ```gts
|
|
80
|
+
* import { Request } from '@warp-drive-mirror/ember';
|
|
81
|
+
*
|
|
82
|
+
* <template>
|
|
83
|
+
* <Request @request={{@request}}>
|
|
84
|
+
* <:loading as |state|>
|
|
85
|
+
* <Spinner @percentDone={{state.completedRatio}} />
|
|
86
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
87
|
+
* </:loading>
|
|
88
|
+
*
|
|
89
|
+
* <:error as |error state|>
|
|
90
|
+
* <ErrorForm @error={{error}} />
|
|
91
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
92
|
+
* </:error>
|
|
93
|
+
*
|
|
94
|
+
* <:content as |data state|>
|
|
95
|
+
* <h1>{{data.title}}</h1>
|
|
96
|
+
* {{#if state.isBackgroundReloading}}
|
|
97
|
+
* <SmallSpinner />
|
|
98
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
99
|
+
* {{else}}
|
|
100
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
101
|
+
* {{/if}}
|
|
102
|
+
* </:content>
|
|
103
|
+
*
|
|
104
|
+
* <:cancelled as |error state|>
|
|
105
|
+
* <h2>The Request was cancelled</h2>
|
|
106
|
+
* <button {{on "click" state.retry}}>Retry</button>
|
|
107
|
+
* </:cancelled>
|
|
108
|
+
*
|
|
109
|
+
* <:idle>
|
|
110
|
+
* <button {{on "click" @kickOffRequest}}>Load Preview?</button>
|
|
111
|
+
* </:idle>
|
|
112
|
+
*
|
|
113
|
+
* </Request>
|
|
114
|
+
* </template>
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* ## Streaming Data
|
|
118
|
+
*
|
|
119
|
+
* The loading state exposes the download `ReadableStream` instance for consumption
|
|
120
|
+
*
|
|
121
|
+
* ```gts
|
|
122
|
+
* import { Request } from '@warp-drive-mirror/ember';
|
|
123
|
+
*
|
|
124
|
+
* <template>
|
|
125
|
+
* <Request @request={{@request}}>
|
|
126
|
+
* <:loading as |state|>
|
|
127
|
+
* <Video @stream={{state.stream}} />
|
|
128
|
+
* </:loading>
|
|
129
|
+
*
|
|
130
|
+
* <:error as |error|>
|
|
131
|
+
* <ErrorForm @error={{error}} />
|
|
132
|
+
* </:error>
|
|
133
|
+
* </Request>
|
|
134
|
+
* </template>
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* ## Retry
|
|
138
|
+
*
|
|
139
|
+
* Cancelled and error'd requests may be retried by calling the `retry` method.
|
|
140
|
+
*
|
|
141
|
+
* Retry will restart the state progression, using the loading, error, cancelled,
|
|
142
|
+
* and content blocks as appropriate.
|
|
143
|
+
*
|
|
144
|
+
* ## Reloading
|
|
145
|
+
*
|
|
146
|
+
* The `reload` method will force the request to be fully re-executed, bypassing
|
|
147
|
+
* cache and restarting the state progression through the loading, error, and
|
|
148
|
+
* content blocks as appropriate.
|
|
149
|
+
*
|
|
150
|
+
* Background reload (refresh) is a special substate of the content state that
|
|
151
|
+
* allows you to refresh the request in the background. This is useful for when
|
|
152
|
+
* you want to update the data in the background without blocking the UI.
|
|
153
|
+
*
|
|
154
|
+
* Reload and refresh are available as methods on the `content` state.
|
|
155
|
+
*
|
|
156
|
+
* ```gts
|
|
157
|
+
* import { Request } from '@warp-drive-mirror/ember';
|
|
158
|
+
*
|
|
159
|
+
* <template>
|
|
160
|
+
* <Request @request={{@request}}>
|
|
161
|
+
* <:content as |data state|>
|
|
162
|
+
* <h1>{{data.title}}</h1>
|
|
163
|
+
* {{#if state.isBackgroundReloading}}
|
|
164
|
+
* <SmallSpinner />
|
|
165
|
+
* <button {{on "click" state.abort}}>Cancel</button>
|
|
166
|
+
* {{/if}}
|
|
167
|
+
*
|
|
168
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
169
|
+
* <button {{on "click" state.reload}}>Reload</button>
|
|
170
|
+
* </:content>
|
|
171
|
+
* </Request>
|
|
172
|
+
* </template>
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* ## Advanced Reloading
|
|
176
|
+
*
|
|
177
|
+
* We can nest our usage of `<Request />` to handle more advanced
|
|
178
|
+
* reloading scenarios.
|
|
179
|
+
*
|
|
180
|
+
* ```gts
|
|
181
|
+
* import { Request } from '@warp-drive-mirror/ember';
|
|
182
|
+
*
|
|
183
|
+
* <template>
|
|
184
|
+
* <Request @request={{@request}}>
|
|
185
|
+
* <:cancelled>
|
|
186
|
+
* <h2>The Request Cancelled</h2>
|
|
187
|
+
* </:cancelled>
|
|
188
|
+
*
|
|
189
|
+
* <:error as |error|>
|
|
190
|
+
* <ErrorForm @error={{error}} />
|
|
191
|
+
* </:error>
|
|
192
|
+
*
|
|
193
|
+
* <:content as |result state|>
|
|
194
|
+
* <Request @request={{state.latestRequest}}>
|
|
195
|
+
* <!-- Handle Background Request -->
|
|
196
|
+
* </Request>
|
|
197
|
+
*
|
|
198
|
+
* <h1>{{result.title}}</h1>
|
|
199
|
+
*
|
|
200
|
+
* <button {{on "click" state.refresh}}>Refresh</button>
|
|
201
|
+
* </:content>
|
|
202
|
+
* </Request>
|
|
203
|
+
* </template>
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ## Autorefresh
|
|
207
|
+
*
|
|
208
|
+
* `<Request />` supports automatic refresh and reload under certain conditions.
|
|
209
|
+
*
|
|
210
|
+
* - `online`: This occurs when a browser window or tab comes back to the foreground
|
|
211
|
+
* after being backgrounded or when the network reports as being online after
|
|
212
|
+
* having been offline.
|
|
213
|
+
* - `interval`: This occurs when a specified amount of time has passed.
|
|
214
|
+
* - `invalid`: This occurs when the store emits a notification that the request
|
|
215
|
+
* has become invalid.
|
|
216
|
+
*
|
|
217
|
+
* You can specify when autorefresh should occur by setting the `autorefresh` arg
|
|
218
|
+
* to `true` or a comma-separated list of the above values.
|
|
219
|
+
*
|
|
220
|
+
* A value of `true` is equivalent to `'online,invalid'`.
|
|
221
|
+
*
|
|
222
|
+
* By default, an autorefresh will only occur if the browser was backgrounded or
|
|
223
|
+
* offline for more than 30s before coming back available. This amount of time can
|
|
224
|
+
* be tweaked by setting the number of milliseconds via `@autorefreshThreshold`.
|
|
225
|
+
*
|
|
226
|
+
* This arg also controls the interval at which the request will be refreshed
|
|
227
|
+
* if the `interval` autorefresh type is enabled.
|
|
228
|
+
*
|
|
229
|
+
* Finally, the behavior of the request initiated by autorefresh can be adjusted
|
|
230
|
+
* by setting the `autorefreshBehavior` arg to `'refresh'`, `'reload'`, or `'policy'`.
|
|
231
|
+
*
|
|
232
|
+
* - `'refresh'`: Refresh the request in the background
|
|
233
|
+
* - `'reload'`: Force a reload of the request
|
|
234
|
+
* - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to
|
|
235
|
+
* reload, refresh, or do nothing.
|
|
236
|
+
*
|
|
237
|
+
* More advanced refresh and reload behaviors can be created by passing the reload and
|
|
238
|
+
* refresh actions into another component. For instance, refresh could be set up on a
|
|
239
|
+
* timer or on a websocket subscription.
|
|
240
|
+
*
|
|
241
|
+
*
|
|
242
|
+
* ```gts
|
|
243
|
+
* import { Request } from '@warp-drive-mirror/ember';
|
|
244
|
+
*
|
|
245
|
+
* <template>
|
|
246
|
+
* <Request @request={{@request}}>
|
|
247
|
+
* <:content as |result state|>
|
|
248
|
+
* <h1>{{result.title}}</h1>
|
|
249
|
+
*
|
|
250
|
+
* <Interval @period={{30_000}} @fn={{state.refresh}} />
|
|
251
|
+
* <Subscribe @channel={{@someValue}} @fn={{state.refresh}} />
|
|
252
|
+
* </:content>
|
|
253
|
+
* </Request>
|
|
254
|
+
* </template>
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* If a matching request is refreshed or reloaded by any other component,
|
|
258
|
+
* the `Request` component will react accordingly.
|
|
259
|
+
*
|
|
260
|
+
* ## Deduping
|
|
261
|
+
*
|
|
262
|
+
* The store dedupes requests by identity. If a request is made for the same identity
|
|
263
|
+
* from multiple `<Request />` components, even if the request is not referentially the
|
|
264
|
+
* same, only one actual request will be made.
|
|
265
|
+
*
|
|
266
|
+
* @category Components
|
|
267
|
+
* @public
|
|
268
|
+
*/ export declare class Request<
|
|
269
|
+
RT,
|
|
270
|
+
E
|
|
271
|
+
> extends Component<RequestSignature<RT, E>> {
|
|
272
|
+
get store(): Store | RequestManager;
|
|
273
|
+
_state: RequestSubscription<RT, E> | null;
|
|
274
|
+
get state(): RequestSubscription<RT, E>;
|
|
275
|
+
/**
|
|
276
|
+
* The chrome component to use for rendering the request.
|
|
277
|
+
*
|
|
278
|
+
* @private
|
|
279
|
+
*/ get Chrome(): ComponentLike<{
|
|
280
|
+
Blocks: {
|
|
281
|
+
default: [];
|
|
282
|
+
};
|
|
283
|
+
Args: {
|
|
284
|
+
state: RequestState | null;
|
|
285
|
+
features: ContentFeatures<RT>;
|
|
286
|
+
};
|
|
287
|
+
}>;
|
|
288
|
+
willDestroy(): void;
|
|
289
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith <project>
|
|
4
|
+
*/
|
|
5
|
+
export { Request, type ContentFeatures, type RecoveryFeatures } from "./-private/request.js";
|
|
6
|
+
export { Await, Throw } from "./-private/await.js";
|
|
7
|
+
export { getRequestState, createRequestSubscription, type RequestLoadingState, type RequestState } from "@warp-drive-mirror/core/store/-private";
|
|
8
|
+
export { getPromiseState, type PromiseState } from "@warp-drive-mirror/core/reactive";
|