@warp-drive/ember 5.7.0-alpha.22 → 5.7.0-alpha.24

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.
@@ -1,4 +1,5 @@
1
1
  import Component from "@glimmer/component";
2
+ import type { ComponentLike } from "@glint/template";
2
3
  import type { Store, StoreRequestInput } from "@warp-drive/core";
3
4
  import type { Future } from "@warp-drive/core/request";
4
5
  import type { RequestLoadingState, RequestState, RequestSubscription } from "@warp-drive/core/store/-private";
@@ -28,6 +29,16 @@ interface RequestSignature<
28
29
  E
29
30
  > {
30
31
  Args: {
32
+ chrome?: ComponentLike<{
33
+ Blocks: {
34
+ default: [];
35
+ };
36
+ Args: {
37
+ state: RequestState | null;
38
+ features: ContentFeatures<RT>;
39
+ };
40
+ }>;
41
+ subscription?: RequestSubscription<RT, E>;
31
42
  /**
32
43
  * The request to monitor. This should be a `Future` instance returned
33
44
  * by either the `store.request` or `store.requestManager.request` methods.
@@ -339,6 +350,19 @@ interface RequestSignature<
339
350
  get store(): Store;
340
351
  _state: RequestSubscription<RT, E> | null;
341
352
  get state(): RequestSubscription<RT, E>;
353
+ /**
354
+ * The chrome component to use for rendering the request.
355
+ *
356
+ * @private
357
+ */ get Chrome(): ComponentLike<{
358
+ Blocks: {
359
+ default: [];
360
+ };
361
+ Args: {
362
+ state: RequestState | null;
363
+ features: ContentFeatures<RT>;
364
+ };
365
+ }>;
342
366
  willDestroy(): void;
343
367
  }
344
368
  export {};
@@ -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) {
@@ -167,6 +183,9 @@ if (macroCondition(moduleExists('ember-provide-consume-context'))) {
167
183
  * Utilities for keeping the request fresh
168
184
  */
169
185
 
186
+ const DefaultChrome = setComponentTemplate(precompileTemplate("{{yield}}", {
187
+ strictMode: true
188
+ }), templateOnly());
170
189
  /**
171
190
  * The `<Request />` component is a powerful tool for managing data fetching and
172
191
  * state in your Ember application. It provides a declarative approach to reactive
@@ -412,21 +431,40 @@ class Request extends Component {
412
431
  const {
413
432
  store
414
433
  } = this;
415
- if (_state && _state.store !== store) {
434
+ const {
435
+ subscription
436
+ } = this.args;
437
+ if (_state && (_state.store !== store || subscription)) {
416
438
  _state[DISPOSE]();
417
439
  _state = null;
418
440
  }
441
+ if (subscription) {
442
+ return subscription;
443
+ }
419
444
  if (!_state) {
420
445
  this._state = _state = createRequestSubscription(store, this.args);
421
446
  }
422
447
  return _state;
423
448
  }
449
+ /**
450
+ * The chrome component to use for rendering the request.
451
+ *
452
+ * @private
453
+ */
454
+ get Chrome() {
455
+ return this.args.chrome || DefaultChrome;
456
+ }
457
+ static {
458
+ decorateMethodV2(this.prototype, "Chrome", [cached]);
459
+ }
424
460
  willDestroy() {
425
- this._state[DISPOSE]();
426
- this._state = null;
461
+ if (this._state) {
462
+ this._state[DISPOSE]();
463
+ this._state = null;
464
+ }
427
465
  }
428
466
  static {
429
- setComponentTemplate(precompileTemplate("\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 ", {
467
+ 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
468
  strictMode: true,
431
469
  scope: () => ({
432
470
  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.22",
4
+ "version": "5.7.0-alpha.24",
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.22"
41
+ "@warp-drive/core": "5.7.0-alpha.24"
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.22",
64
- "@warp-drive/core": "5.7.0-alpha.22",
63
+ "@warp-drive/internal-config": "5.7.0-alpha.24",
64
+ "@warp-drive/core": "5.7.0-alpha.24",
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",