-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
rfc: ember-data | deprecate-non-strict-types #740
Merged
runspired
merged 1 commit into
emberjs:master
from
runspired:ember-data/deprecate-non-strict-types
Jul 24, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
text/0740-ember-data-deprecate-non-strict-relationships.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
Stage: Accepted | ||
Start Date: 2021-04-23 | ||
Release Date: Unreleased | ||
Release Versions: | ||
ember-source: vX.Y.Z | ||
ember-data: vX.Y.Z | ||
Relevant Team(s): ember-data | ||
RFC PR: https://github.com/emberjs/rfcs/pull/740 | ||
--- | ||
|
||
# EmberData | Deprecate Non Strict Types | ||
|
||
## Summary | ||
|
||
Deprecates when the `type` for a record provided by a user differs from the resolved | ||
type, thereby removing the need to configure `ember-inflector` to treat `types` as `uncountable` | ||
in order to use plural model names, and removing the dasherization constraint. | ||
|
||
## Motivation | ||
|
||
Today, `ember-data` normalizes user supplied `type` or `modelName` anywhere it is encountered | ||
so that it will match the `type` we expect to provide to ember's resolver to lookup and create | ||
instances of `Model`/`Adapter`/`Serializer`. | ||
|
||
In practice, this resulted in a convention of singularized, dasherized modelName arguments and | ||
`type` fields in payloads. However, this convention is unimportant to how EmberData operates and | ||
we feel that users should be able to name their models however they like provided that (1) they | ||
use their format consistently and (2) that format matches what ember's resolver needs to resolve | ||
any necessary modules (such as models). | ||
|
||
Today, if you wanted to name a model `posts`, you could achieve this by | ||
|
||
- explicitly definining the inverse type on all relationships pointing at `posts` | ||
- using `posts` as the type in all payloads provided to the store | ||
- naming your model on disk as `models/posts.js` | ||
- configuring `ember-inflector` to treat `posts` as either uncountable or as it's own singular/plural. | ||
|
||
While the first three items here are strict conventions, we would like to do away with the necessity of | ||
configuring `ember-inflector` in this manner. | ||
|
||
Similarly, if you want to name your models with camelCase or SnakeCase types instead of dasherized types | ||
we see no reason to enforce that you do otherwise. | ||
|
||
In this sense the name of this RFC may at first feel in opposition to the motivation: we are proposing | ||
deprecating non-strict usage of types so that we can loosen restrictions on type usage. | ||
|
||
By removing support for non-strict we *strictly* mean removing support for using types in a way that | ||
depends upon our normalization in order for resolver lookups to succeed. | ||
|
||
## Detailed design | ||
|
||
We would print a deprecation whenever our normalization results in a different string than the string originally | ||
received. This deprecation would target `5.0` and become `enabled` no-sooner than `4.1` although it may be made | ||
`available` before then. | ||
|
||
To resolve issues with `dasherization`, users would need to dasherize in advance of providing data or arguments | ||
to `store` methods (generally this is done in the serializer's normalization hooks for payloads and at | ||
call-sights for method args that take `modelName`). | ||
|
||
To resolve issues with `singularization`, users would need either to configure `ember-inflector` to return the | ||
desired form for their string if the supplied string is the desired singular/plural, or singularize the string | ||
in advance. | ||
|
||
Once a user has resolved this deprecation and marked their app as compatible with the version of `ember-data` | ||
in which this deprecation became enabled all support for ember-data's normalization will be removed at build | ||
time and users may supply types in any format so long as their usage is (1) consistent and (2) resolveable. | ||
|
||
## How we teach this | ||
|
||
Generally these changes remove a thing to be taught (that all types anywhere in a payload or as args should | ||
be normalized to the singular+dasherized form) in favor of teaching that usage of a `type` should be consistent | ||
and that the name of the `model` should match what is being used as `type`. | ||
|
||
## Drawbacks | ||
|
||
Potentially some churn if it turns out that lots of users rely on the dasherization aspect. We already stopped | ||
singularizing on our own some time ago except in the case of hasMany relationship definitions. We can mitigate | ||
this to a good degree by making sure that the default serializers dasherize their output if they do not already. | ||
|
||
## Alternatives | ||
|
||
Continue to enforce dasherized-singular types and pay the cost of requiring use of `ember-inflector` if using | ||
`ember-data`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend clarifying what "resolved" means in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resolved type means the on-disk file-path derived type. So for instance a model at
app/models/foos/otherUsers.js
has the resolved typefoos/otherUsers
whileapp/models/foos/bar-user.js
has the resolved typefoos/bar-user
. For the latter example,foos/barUser
andfoos/barUsers
could both currently be supplied to ember-data in most contexts today and still result in a successful lookup of the model. Said uses would be required to be refactored to use the resolved type.I'll try to add a note to this effect to the RFC for clarification.