Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE beta] Add an optional feature "no-implicit-route-model" to allow the removal of the implicit loading of a model per RFC #774 #20639

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/@ember/-internals/environment/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ export const ENV = {
*/
_DEFAULT_ASYNC_OBSERVERS: false,

/**
Whether the app still has default record-loading behavior in the model
hook from RFC https://rfcs.emberjs.com/id/0774-implicit-record-route-loading
This will also remove the default store property from the route.
This is not intended to be set directly, as the implementation may change in
the future. Use `@ember/optional-features` instead.
@property _NO_IMPLICIT_ROUTE_MODEL
@for EmberENV
@type Boolean
@default false
@private
*/
_NO_IMPLICIT_ROUTE_MODEL: false,

/**
Controls the maximum number of scheduled rerenders without "settling". In general,
applications should not need to modify this environment variable, but please
Expand Down
4 changes: 4 additions & 0 deletions packages/@ember/routing/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@ember/-internals/metal';
import type Owner from '@ember/owner';
import { getOwner } from '@ember/-internals/owner';
import { ENV } from '@ember/-internals/environment';
import { BucketCache } from '@ember/routing/-internals';
import EmberObject, { computed, get, set, getProperties, setProperties } from '@ember/object';
import Evented from '@ember/object/evented';
Expand Down Expand Up @@ -1251,6 +1252,9 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
@private
*/
findModel(type: string, value: unknown) {
if (ENV._NO_IMPLICIT_ROUTE_MODEL) {
return;
}
deprecate(
`The implicit model loading behavior for routes is deprecated. ` +
`Please define an explicit model hook for ${this.fullRouteName}.`,
Expand Down
12 changes: 12 additions & 0 deletions packages/@ember/routing/tests/system/route_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setOwner } from '@ember/-internals/owner';
import { ENV } from '@ember/-internals/environment';
import { runDestroy, buildOwner, moduleFor, AbstractTestCase } from 'internal-test-helpers';
import Service, { service } from '@ember/service';
import EmberObject from '@ember/object';
Expand All @@ -22,6 +23,17 @@ moduleFor(
route = routeOne = routeTwo = lookupHash = undefined;
}

['@test noops if _NO_IMPLICIT_ROUTE_MODEL is true'](assert) {
this._NO_IMPLICIT_ROUTE_MODEL = ENV._NO_IMPLICIT_ROUTE_MODEL;
ENV._NO_IMPLICIT_ROUTE_MODEL = true;
assert.equal(
route.findModel('post', 1),
undefined,
'When _NO_IMPLICIT_ROUTE_MODEL is true, findModel does nothing'
);
ENV._NO_IMPLICIT_ROUTE_MODEL = this._NO_IMPLICIT_ROUTE_MODEL;
}

['@test default store utilizes the container to acquire the model factory'](assert) {
assert.expect(5);

Expand Down
1 change: 1 addition & 0 deletions tests/docs/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'_APPLICATION_TEMPLATE_WRAPPER',
'_DEBUG_RENDER_TREE',
'_DEFAULT_ASYNC_OBSERVERS',
'_NO_IMPLICIT_ROUTE_MODEL',
'_RERENDER_LOOP_LIMIT',
'_TEMPLATE_ONLY_GLIMMER_COMPONENTS',
'Input',
Expand Down
Loading