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

Place store on Ember.Route to maintain default store behaviour #7777

Closed
wants to merge 5 commits into from
Closed
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
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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ jobs:
run: yarn test

external-partners:
needs: [additional-scenarios, basic-tests, floating-dependencies, lint, lts, releases]
needs: [additional-scenarios, basic-tests, floating-dependencies, lint, lts]
if: |
github.event_name == 'pull_request' && (
github.base_ref == 'master' || github.base_ref == 'beta'
github.base_ref == 'master' || github.base_ref == 'beta' || github.base_ref == 'release'
) || github.event_name == 'push' && (
endsWith(github.ref, '/master') || endsWith(github.ref, '/beta')
endsWith(github.ref, '/master') || endsWith(github.ref, '/beta') || endsWith(github.ref, '/release')
)
runs-on: ubuntu-latest
strategy:
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,8 +1,12 @@
import { getOwner } from '@ember/application';
import { deprecate } from '@ember/debug';
import Route from '@ember/routing/route';
import { DEBUG } from '@glimmer/env';

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

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

function initializeStore(application) {
// we can just use registerOptionsForType when we no longer
// support (deprecated) versions of @ember/test-helpers
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);
}