|
| 1 | +--- |
| 2 | +stage: accepted |
| 3 | +start-date: 2024-05-11T00:00:00.000Z |
| 4 | +release-date: # In format YYYY-MM-DDT00:00:00.000Z |
| 5 | +release-versions: |
| 6 | +teams: # delete teams that aren't relevant |
| 7 | + - data |
| 8 | +prs: |
| 9 | + accepted: https://github.com/emberjs/rfcs/pull/1026 |
| 10 | +project-link: |
| 11 | +suite: |
| 12 | +--- |
| 13 | + |
| 14 | +# EmberData | Deprecate Store extending EmberObject |
| 15 | + |
| 16 | +## Summary |
| 17 | + |
| 18 | +This RFC deprecates the Store extending from EmberObject. All EmberObject specific |
| 19 | +APIs included. |
| 20 | + |
| 21 | +## Motivation |
| 22 | + |
| 23 | +There are two motivations: |
| 24 | + |
| 25 | +First, extending EmberObject is vestigial. The Store makes no use of any EmberObject API, |
| 26 | +not even for use with Ember's container or service injection. |
| 27 | + |
| 28 | +Second, in order to support any Ember version, support any non-Ember framework, and support |
| 29 | +EmberData running in non-browser environments we want to remove unnecessary coupling to the Ember framework. |
| 30 | + |
| 31 | +## Detailed design |
| 32 | + |
| 33 | +Instead of deprecating every EmberObject method, we will feature flag the Store extending |
| 34 | +EmberObject at the module level. This ensures the deprecation only prints once, and that |
| 35 | +once resolved the Store will no longer extend thereby making it feasible to utilize the |
| 36 | +benefits of not extending EmberObject immediately. |
| 37 | + |
| 38 | +To resolve the deprecation, users will need to confirm they are not using EmberObject APIs |
| 39 | +on the Store. Generally speaking, this has been limited to `.extend` e.g. |
| 40 | + |
| 41 | +```ts |
| 42 | +const AppStore = Store.extend({}); |
| 43 | +``` |
| 44 | + |
| 45 | +This pattern is now rare in the wild, but where it exists can be safely refactored to |
| 46 | + |
| 47 | +```ts |
| 48 | +class AppStore extends Store {} |
| 49 | +``` |
| 50 | + |
| 51 | +Once confirmed (or in order to confirm) that the Store in an app no longer requires |
| 52 | +extending EmberObject, the deprecation config boolean may be used to both remove the |
| 53 | +deprecation AND the deprecated code. |
| 54 | + |
| 55 | +```ts |
| 56 | +const app = new EmberApp(defaults, { |
| 57 | + emberData: { |
| 58 | + deprecations: { |
| 59 | + DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: false |
| 60 | + } |
| 61 | + } |
| 62 | +}); |
| 63 | +``` |
| 64 | + |
| 65 | +An upcoming shift in how EmberData manages configuration would mean that applications |
| 66 | +using the new configuration (not yet released) would do the following: |
| 67 | + |
| 68 | +```ts |
| 69 | +'use strict'; |
| 70 | + |
| 71 | +const EmberApp = require('ember-cli/lib/broccoli/ember-app'); |
| 72 | + |
| 73 | +module.exports = async function (defaults) { |
| 74 | + const { setConfig } = await import('@warp-drive/build-config'); |
| 75 | + |
| 76 | + const app = new EmberApp(defaults, {}); |
| 77 | + |
| 78 | + setConfig(app, __dirname, { |
| 79 | + deprecations: { |
| 80 | + DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: false |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + return app.toTree(); |
| 85 | +}; |
| 86 | +``` |
| 87 | + |
| 88 | +## How we teach this |
| 89 | + |
| 90 | +Guides would be added for this deprecation to both the deprecation app and the API docs. |
| 91 | + |
| 92 | +Generally, folks do not tend to treat the Store as an EmberObject or utilize legacy EmberObject |
| 93 | +APIs with it, so both the teaching and the migration overhead are low. |
| 94 | + |
| 95 | +## Drawbacks |
| 96 | + |
| 97 | +none |
| 98 | + |
| 99 | +## Alternatives |
| 100 | + |
| 101 | +- deprecate every classic method to help folks find usage |
| 102 | + - not chosen as it's rare *and* setting the deprecation flag to `false` will cause any such locations to be findable via error |
| 103 | +- create a new package `@warp-drive/core` or `@warp-drive/store` and have users migrate by swapping import |
| 104 | + locations. |
| 105 | + - not chosen as this is too minimal a change |
| 106 | + |
| 107 | +## Unresolved questions |
| 108 | + |
| 109 | +None |
0 commit comments