ember-source 5.3.0-alpha.3 → 5.3.0-alpha.5

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.
@@ -5,5 +5,5 @@
5
5
  * Portions Copyright 2008-2011 Apple Inc. All rights reserved.
6
6
  * @license Licensed under MIT license
7
7
  * See https://raw.github.com/emberjs/ember.js/master/LICENSE
8
- * @version 5.3.0-alpha.3
8
+ * @version 5.3.0-alpha.5
9
9
  */
@@ -16,7 +16,7 @@ import { ActionHandler } from '@ember/-internals/runtime';
16
16
  import { isEmpty, typeOf } from '@ember/utils';
17
17
  import { isProxy, lookupDescriptor } from '@ember/-internals/utils';
18
18
  import Controller from '@ember/controller';
19
- import { assert, info, isTesting } from '@ember/debug';
19
+ import { assert, deprecate, info, isTesting } from '@ember/debug';
20
20
  import EngineInstance from '@ember/engine/instance';
21
21
  import { dependentKeyCompat } from '@ember/object/compat';
22
22
  import { once } from '@ember/runloop';
@@ -25,6 +25,9 @@ import { PARAMS_SYMBOL, STATE_SYMBOL } from 'router_js';
25
25
  import EmberRouter from '@ember/routing/router';
26
26
  import { generateController } from '@ember/routing/-internals';
27
27
  import { calculateCacheKey, normalizeControllerQueryParams, prefixRouteNameArg, stashParamNames } from './lib/utils';
28
+ function isStoreLike(store) {
29
+ return typeof store === 'object' && store !== null && typeof store.find === 'function';
30
+ }
28
31
  export const ROUTE_CONNECTIONS = new WeakMap();
29
32
  const RENDER = Symbol('render');
30
33
  class Route extends EmberObject.extend(ActionHandler, Evented) {
@@ -508,12 +511,6 @@ class Route extends EmberObject.extend(ActionHandler, Evented) {
508
511
  });
509
512
  export default Router;
510
513
  ```
511
- The model for the `post` route is `store.findRecord('post', params.post_id)`.
512
- By default, if your route has a dynamic segment ending in `_id`:
513
- * The model class is determined from the segment (`post_id`'s
514
- class is `App.Post`)
515
- * The find method is called on the model class with the value of
516
- the dynamic segment.
517
514
  Note that for routes with dynamic segments, this hook is not always
518
515
  executed. If the route is entered through a transition (e.g. when
519
516
  using the `link-to` Handlebars helper or the `transitionTo` method
@@ -539,11 +536,18 @@ class Route extends EmberObject.extend(ActionHandler, Evented) {
539
536
  described in the documentation for `beforeModel`. In particular,
540
537
  if a promise returned from `model` fails, the error will be
541
538
  handled by the `error` hook on `Route`.
539
+ Note that the legacy behavior of automatically defining a model
540
+ hook when a dynamic segment ending in `_id` is present is
541
+ [deprecated](https://deprecations.emberjs.com/v5.x#toc_deprecate-implicit-route-model).
542
+ You should explicitly define a model hook whenever any segments are
543
+ present.
542
544
  Example
543
545
  ```app/routes/post.js
544
546
  import Route from '@ember/routing/route';
547
+ import { service } from '@ember/service';
545
548
  export default class PostRoute extends Route {
546
- model(params) {
549
+ @service store;
550
+ model(params) {
547
551
  return this.store.findRecord('post', params.post_id);
548
552
  }
549
553
  }
@@ -604,14 +608,19 @@ class Route extends EmberObject.extend(ActionHandler, Evented) {
604
608
  @param {Object} value the value passed to find
605
609
  @private
606
610
  */
607
- findModel(...args) {
608
- // SAFETY: it's all absurd lies; there is no explicit contract for `store`
609
- // and we allow people to register *anything* here and we call it: GLHF! The
610
- // fallback path here means we correctly handle the case where there is no
611
- // explicit store injection on the route subclass.
612
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
613
- let store = 'store' in this ? this.store : get(this, '_store');
614
- return store.find(...args);
611
+ findModel(type, value) {
612
+ deprecate(`The implicit model loading behavior for routes is deprecated. ` + `Please define an explicit model hook for ${this.fullRouteName}.`, false, {
613
+ id: 'deprecate-implicit-route-model',
614
+ for: 'ember-source',
615
+ since: {
616
+ available: '5.3.0'
617
+ },
618
+ until: '6.0.0'
619
+ });
620
+ const store = 'store' in this ? this.store : get(this, '_store');
621
+ assert('Expected route to have a store with a find method', isStoreLike(store));
622
+ // SAFETY: We don't actually know it will return this, but this code path is also deprecated.
623
+ return store.find(type, value);
615
624
  }
616
625
  /**
617
626
  A hook you can use to setup the controller for the current route.
@@ -625,8 +634,10 @@ class Route extends EmberObject.extend(ActionHandler, Evented) {
625
634
  `super`:
626
635
  ```app/routes/photos.js
627
636
  import Route from '@ember/routing/route';
637
+ import { service } from '@ember/service';
628
638
  export default class PhotosRoute extends Route {
629
- model() {
639
+ @service store;
640
+ model() {
630
641
  return this.store.findAll('photo');
631
642
  }
632
643
  setupController(controller, model) {
@@ -806,16 +817,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) {
806
817
  }
807
818
  return params;
808
819
  }
809
- /**
810
- Store property provides a hook for data persistence libraries to inject themselves.
811
- By default, this store property provides the exact same functionality previously
812
- in the model hook.
813
- Currently, the required interface is:
814
- `store.find(modelName, findArguments)`
815
- @property store
816
- @type {Object}
817
- @private
818
- */
820
+ /** @deprecated Manually define your own store, such as with `@service store` */
819
821
  get _store() {
820
822
  const owner = getOwner(this);
821
823
  assert('Route is unexpectedly missing an owner', owner);
@@ -1 +1 @@
1
- export default "5.3.0-alpha.3";
1
+ export default "5.3.0-alpha.5";