Skip to content

Commit 12106b7

Browse files
authored
Merge pull request #20639 from emberjs/kg-add-deprecation-optional-feature
[FEATURE] Add an optional feature "no-implicit-route-model" to allow the removal of the implicit loading of a model per RFC #774
2 parents be51c93 + 931c9d2 commit 12106b7

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

packages/@ember/-internals/environment/lib/env.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ export const ENV = {
142142
*/
143143
_DEFAULT_ASYNC_OBSERVERS: false,
144144

145+
/**
146+
Whether the app still has default record-loading behavior in the model
147+
hook from RFC https://rfcs.emberjs.com/id/0774-implicit-record-route-loading
148+
This will also remove the default store property from the route.
149+
150+
This is not intended to be set directly, as the implementation may change in
151+
the future. Use `@ember/optional-features` instead.
152+
153+
@property _NO_IMPLICIT_ROUTE_MODEL
154+
@for EmberENV
155+
@type Boolean
156+
@default false
157+
@private
158+
*/
159+
_NO_IMPLICIT_ROUTE_MODEL: false,
160+
145161
/**
146162
Controls the maximum number of scheduled rerenders without "settling". In general,
147163
applications should not need to modify this environment variable, but please

packages/@ember/routing/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@ember/-internals/metal';
88
import type Owner from '@ember/owner';
99
import { getOwner } from '@ember/-internals/owner';
10+
import { ENV } from '@ember/-internals/environment';
1011
import { BucketCache } from '@ember/routing/-internals';
1112
import EmberObject, { computed, get, set, getProperties, setProperties } from '@ember/object';
1213
import Evented from '@ember/object/evented';
@@ -1251,6 +1252,9 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
12511252
@private
12521253
*/
12531254
findModel(type: string, value: unknown) {
1255+
if (ENV._NO_IMPLICIT_ROUTE_MODEL) {
1256+
return;
1257+
}
12541258
deprecate(
12551259
`The implicit model loading behavior for routes is deprecated. ` +
12561260
`Please define an explicit model hook for ${this.fullRouteName}.`,

packages/@ember/routing/tests/system/route_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { setOwner } from '@ember/-internals/owner';
2+
import { ENV } from '@ember/-internals/environment';
23
import { runDestroy, buildOwner, moduleFor, AbstractTestCase } from 'internal-test-helpers';
34
import Service, { service } from '@ember/service';
45
import EmberObject from '@ember/object';
@@ -22,6 +23,17 @@ moduleFor(
2223
route = routeOne = routeTwo = lookupHash = undefined;
2324
}
2425

26+
['@test noops if _NO_IMPLICIT_ROUTE_MODEL is true'](assert) {
27+
this._NO_IMPLICIT_ROUTE_MODEL = ENV._NO_IMPLICIT_ROUTE_MODEL;
28+
ENV._NO_IMPLICIT_ROUTE_MODEL = true;
29+
assert.equal(
30+
route.findModel('post', 1),
31+
undefined,
32+
'When _NO_IMPLICIT_ROUTE_MODEL is true, findModel does nothing'
33+
);
34+
ENV._NO_IMPLICIT_ROUTE_MODEL = this._NO_IMPLICIT_ROUTE_MODEL;
35+
}
36+
2537
['@test default store utilizes the container to acquire the model factory'](assert) {
2638
assert.expect(5);
2739

tests/docs/expected.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'_APPLICATION_TEMPLATE_WRAPPER',
1111
'_DEBUG_RENDER_TREE',
1212
'_DEFAULT_ASYNC_OBSERVERS',
13+
'_NO_IMPLICIT_ROUTE_MODEL',
1314
'_RERENDER_LOOP_LIMIT',
1415
'_TEMPLATE_ONLY_GLIMMER_COMPONENTS',
1516
'Input',

0 commit comments

Comments
 (0)