Skip to content

Commit

Permalink
Place store on Ember.Route to maintain default store behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Nov 24, 2021
1 parent aaff64b commit bebd253
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = {
WeakMap: true,
Set: true,
Promise: false,
Symbol: true,
},
env: {
browser: true,
Expand Down
34 changes: 34 additions & 0 deletions packages/-ember-data/addon/setup-container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { getOwner } from '@ember/application';
import { deprecate } from '@ember/debug';
import Route from '@ember/routing/route';
import { DEBUG } from '@glimmer/env';

const EMBER_DATA_STORE = Symbol('ember-data-store');

import Store from '@ember-data/store';

function initializeStore(application) {
Expand Down Expand Up @@ -46,6 +50,36 @@ function initializeStore(application) {
}
}

// Implicit injection was removed. This is a replacement for Ember Route implicit store for >= v4.0
Route.reopen({
get store() {
if (this[EMBER_DATA_STORE]) {
return this[EMBER_DATA_STORE];
}

const store = getOwner(this).lookup('service:store');
this[EMBER_DATA_STORE] = store;

deprecate(
'In 4.0, ember and ember-data removed implicitly injecting the store on all Ember framework objects. However, Ember.Route still needs to support a default store and it looks like you do not have an explicit `@service store` on your Route. Please add this service injection to your Route.',
false,
{
id: 'ember-data:implicit-store-on-route',
until: '5.0',
since: {
available: '4.0',
enabled: '4.0',
},
}
);

return store;
},
set store(value) {
this[EMBER_DATA_STORE] = value;
},
});

export default function setupContainer(application) {
initializeStore(application);
}

0 comments on commit bebd253

Please sign in to comment.