Skip to content

Commit

Permalink
feat: deprecate store extending EmberObject (#9403)
Browse files Browse the repository at this point in the history
* feat: deprecate store extending EmberObject

* add deprecation notice

* strip store in tests

* update docs test

* fix doc comment
  • Loading branch information
runspired committed May 11, 2024
1 parent 5bd3825 commit 8fb8057
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const DEPRECATE_LEGACY_IMPORTS: boolean;
export const DEPRECATE_NON_UNIQUE_PAYLOADS: boolean;
export const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: boolean;
export const DEPRECATE_MANY_ARRAY_DUPLICATES: boolean;
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: boolean;
14 changes: 14 additions & 0 deletions packages/private-build-infra/virtual-packages/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,17 @@ export const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE = '5.3';
* @public
*/
export const DEPRECATE_MANY_ARRAY_DUPLICATES = '5.3';

/**
* **id: ember-data:deprecate-store-extends-ember-object**
*
* When the flag is `true` (default), the Store class will extend from `@ember/object`.
* When the flag is `false` or `ember-source` is not present, the Store will not extend
* from EmberObject.
*
* @property DEPRECATE_STORE_EXTENDS_EMBER_OBJECT
* @since 5.4
* @until 6.0
* @public
*/
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = '5.4';
54 changes: 46 additions & 8 deletions packages/store/src/-private/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
@module @ember-data/store
*/
// this import location is deprecated but breaks in 4.8 and older
import { assert } from '@ember/debug';
import EmberObject from '@ember/object';
import { assert, deprecate } from '@ember/debug';
import type EmberObject from '@ember/object';

import { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';

import type RequestManager from '@ember-data/request';
import type { Future } from '@ember-data/request/-private/types';
import { LOG_PAYLOADS, LOG_REQUESTS } from '@warp-drive/build-config/debugging';
import { DEPRECATE_STORE_EXTENDS_EMBER_OBJECT } from '@warp-drive/build-config/deprecations';
import { DEBUG, TESTING } from '@warp-drive/build-config/env';
import type { Graph } from '@warp-drive/core-types/graph';
import type {
Expand Down Expand Up @@ -106,16 +109,52 @@ export type CreateRecordProperties<T = MaybeHasId & Record<string, unknown>> = T
* export default class extends Store {}
* ```
*
* Most Ember applications will only have a single `Store` configured as a Service
* Most Applications will only have a single `Store` configured as a Service
* in this manner. However, setting up multiple stores is possible, including using
* each as a unique service.
* each as a unique service or within a specific context.
*
@class Store
@public
*/
const EmptyClass = class {};
const BaseClass = macroCondition(dependencySatisfies('ember-source', '*'))
? DEPRECATE_STORE_EXTENDS_EMBER_OBJECT
? (importSync('@ember/object') as typeof import('@ember/object')).default
: EmptyClass
: EmptyClass;

if (BaseClass !== EmptyClass) {
deprecate(
`The Store class extending from EmberObject is deprecated.
Please remove usage of EmberObject APIs and mark your class as not requiring it.
To mark the class as no longer extending from EmberObject, in ember-cli-build.js
set the following config:
\`\`\`js
const app = new EmberApp(defaults, {
emberData: {
deprecations: {
DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: false
}
}
});
\`\`\`
`,
false,
{
id: 'ember-data:deprecate-store-extends-ember-object',
until: '6.0',
for: 'ember-data',
since: {
available: '5.4',
enabled: '5.4',
},
}
);
}

// @ts-expect-error
interface Store {
createRecordDataFor?(identifier: StableRecordIdentifier, wrapper: CacheCapabilitiesManager): Cache | CacheV1;

Expand All @@ -129,7 +168,7 @@ interface Store {
teardownRecord(record: OpaqueRecordInstance): void;
}

class Store extends EmberObject {
class Store extends BaseClass {
declare recordArrayManager: RecordArrayManager;

/**
Expand Down Expand Up @@ -267,7 +306,7 @@ class Store extends EmberObject {
@private
*/
constructor(createArgs?: unknown) {
// @ts-expect-error ember-source types improperly expect createArgs to be `Owner`
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
super(createArgs);
Object.assign(this, createArgs);

Expand Down Expand Up @@ -2200,7 +2239,6 @@ class Store extends EmberObject {
return cache;
}

// @ts-expect-error
destroy(): void {
if (this.isDestroyed) {
// @ember/test-helpers will call destroy multiple times
Expand Down
1 change: 1 addition & 0 deletions tests/docs/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = {
'(public) @warp-drive/build-config/deprecations CurrentDeprecations#DEPRECATE_NON_STRICT_TYPES',
'(public) @warp-drive/build-config/deprecations CurrentDeprecations#DEPRECATE_NON_UNIQUE_PAYLOADS',
'(public) @warp-drive/build-config/deprecations CurrentDeprecations#DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE',
'(public) @warp-drive/build-config/deprecations CurrentDeprecations#DEPRECATE_STORE_EXTENDS_EMBER_OBJECT',
'(public) @ember-data/legacy-compat/builders @ember-data/legacy-compat/builders#findAll',
'(public) @ember-data/legacy-compat/builders @ember-data/legacy-compat/builders#findRecord',
'(public) @ember-data/legacy-compat/builders @ember-data/legacy-compat/builders#query',
Expand Down
2 changes: 2 additions & 0 deletions tests/main/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module.exports = function (defaults) {
features: require('@ember-data/private-build-infra/src/features')(isProd),
env: require('@ember-data/private-build-infra/src/utilities/get-env')(),
};
config.deprecations.DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = false;

const app = new EmberApp(defaults, {
emberData: Object.assign({}, config),
babel: {
Expand Down

0 comments on commit 8fb8057

Please sign in to comment.