UNPKG

1.93 kBJavaScriptView Raw
1import { deprecate } from '@ember/debug';
2import { DEBUG } from '@glimmer/env';
3
4import Store from '@ember-data/store';
5
6function initializeStore(application) {
7 // we can just use registerOptionsForType when we no longer
8 // support (deprecated) versions of @ember/test-helpers
9 // We're issuing a "private-api" deprecation for users of the
10 // deprecated @ember/test-helpers versions, but will keep
11 // this for as long as until 4.0 as needed
12 if (DEBUG && !application.registerOptionsForType) {
13 deprecate(
14 `Deprecated test syntax usage detected!\n\n\t` +
15 `This test relies on a deprecated test setup that is no longer supported by EmberData.` +
16 ` To resolve this you will need to be on a recent version of @ember/test-helpers` +
17 ` AND your tests must use \`setApplication()\` instead of \`setResolver()\` and` +
18 ` \`module()\` with \`setup*Test()\`instead of \`moduleFor*()\`.`,
19 false,
20 {
21 id: 'ember-data:legacy-test-helper-support',
22 until: '3.17',
23 }
24 );
25
26 application.optionsForType('serializer', { singleton: false });
27 application.optionsForType('adapter', { singleton: false });
28
29 if (!application.has('service:store')) {
30 application.register('service:store', Store);
31 }
32
33 return;
34 }
35
36 application.registerOptionsForType('serializer', { singleton: false });
37 application.registerOptionsForType('adapter', { singleton: false });
38
39 if (!application.hasRegistration('service:store')) {
40 application.register('service:store', Store);
41 }
42}
43
44function initializeStoreInjections(application) {
45 let inject = application.inject || application.injection;
46 inject.call(application, 'controller', 'store', 'service:store');
47 inject.call(application, 'route', 'store', 'service:store');
48}
49
50export default function setupContainer(application) {
51 initializeStoreInjections(application);
52 initializeStore(application);
53}