Skip to content

Commit 7966627

Browse files
committed
Deprecate default route store
1 parent cea1c3b commit 7966627

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/@ember/routing/route.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,9 @@ class Route<T = unknown>
15011501
}
15021502
);
15031503

1504+
this._disableStoreDeprecation = true;
15041505
const store = get(this, 'store');
1506+
this._disableStoreDeprecation = false;
15051507
assert('Expected route to have a store with a find method', isStoreLike(store));
15061508

15071509
return store.find(type, value);
@@ -1831,6 +1833,14 @@ class Route<T = unknown>
18311833
return params;
18321834
}
18331835

1836+
/**
1837+
* Set to true to disable the built-in store deprecation warning.
1838+
* This helps avoid double calls from the `findModel` hook.
1839+
*
1840+
* @private
1841+
*/
1842+
_disableStoreDeprecation = false;
1843+
18341844
/**
18351845
Store property provides a hook for data persistence libraries to inject themselves.
18361846
@@ -1843,10 +1853,23 @@ class Route<T = unknown>
18431853
18441854
@property store
18451855
@type {Object}
1856+
@deprecated Manually define your own store, such as with `@service store`
18461857
@private
18471858
*/
18481859
@computed
18491860
protected get store() {
1861+
deprecate(
1862+
`The default store behavior for routes is deprecated. Please define an ` +
1863+
`explicit store for ${this.fullRouteName}, such as with \`@service store\`.`,
1864+
this._disableStoreDeprecation,
1865+
{
1866+
id: 'deprecate-defaul-route-store',
1867+
for: 'ember-source',
1868+
since: { available: '4.12.0' },
1869+
until: '6.0.0',
1870+
}
1871+
);
1872+
18501873
const owner = getOwner(this);
18511874
assert('Route is unexpectedly missing an owner', owner);
18521875
let routeName = this.routeName;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ moduleFor(
6767
runDestroy(owner);
6868
}
6969

70+
['@test default store is deprecated']() {
71+
let owner = buildOwner();
72+
setOwner(route, owner);
73+
74+
expectDeprecation(() => route.store, /The default store behavior for routes is deprecated./);
75+
76+
runDestroy(owner);
77+
}
78+
79+
['@test default store can be overridden'](assert) {
80+
runDestroy(route);
81+
82+
let calledFind = false;
83+
route = EmberRoute.extend({
84+
store: {
85+
find() {
86+
calledFind = true;
87+
},
88+
},
89+
}).create();
90+
91+
route.store.find();
92+
assert.true(calledFind, 'store.find was called');
93+
}
94+
7095
["@test assert if 'store.find' method is not found"]() {
7196
runDestroy(route);
7297

0 commit comments

Comments
 (0)