-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into advance-rfc-0811
- Loading branch information
Showing
22 changed files
with
2,337 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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,89 @@ | ||
--- | ||
stage: accepted | ||
start-date: 2021-11-14 | ||
release-date: | ||
release-versions: | ||
teams: # delete teams that aren't relevant | ||
- framework | ||
prs: | ||
accepted: https://github.com/emberjs/rfcs/pull/774 | ||
--- | ||
|
||
# Deprecate Implicit Record Loading in Routes | ||
|
||
## Summary | ||
|
||
This RFC seeks to deprecate and remove the default record loading behaviour on Ember's Route. By consequence, this will also deprecate and remove the default store on every Route. This behaviour is likely something you either know you have or do not know but it may be occuring in your app. | ||
|
||
```js | ||
export default class PostRoute extends Route { | ||
beforeModel() { | ||
// do stuff | ||
} | ||
|
||
afterModel() { | ||
// do stuff | ||
} | ||
} | ||
``` | ||
|
||
In this example, the `model` hook is not defined. However, Ember will attempt to try a few things before rendering this route's template. | ||
|
||
1. If there is a `store` property on your route, it will attempt to call it's `find` method. Assuming you have `ember-data` installed, you may be expecting this. The arguments will be extracted from the params. | ||
a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and find a record of type `post`. | ||
|
||
2. As a fallback, it will attempt to define a `find` method and use your `Model` instance's find method to fetch. If a `Model` cannot be found or if the found `Model` does not have a `find` method, an assertion is thrown. | ||
|
||
## Motivation | ||
|
||
If a user does not define a `model` hook, a side effect of going to the network has long confused developers. Users have come to associate `Route.model()` with a hook that returns `ember-data` models in the absense of explicit injection. While this can be true, it is not wholly true. New patterns of data loading are becoming accepted in the community including opting to fetch data in a Component or using different libraries. | ||
|
||
By removing this behaviour, we will encourage developers to explicitly define what data is being fetched and from where. | ||
|
||
## Detailed design | ||
|
||
We will issue a deprecation to [`findModel`](https://github.com/emberjs/ember.js/blob/017b11e2f58880869a5b8c647bf7f3199fc07f26/packages/%40ember/-internals/routing/lib/system/route.ts#L1376) notifying the user that if they want to continue this behaviour of attempting to fetch a resource implicitly, they should try and replicate with their own explicitly defined `model` hook. | ||
|
||
In addition, we will include an [optional feature](https://github.com/emberjs/ember-optional-features) to disable this feature and clear the deprecation. | ||
|
||
In v6.0.0, we will remove `findModel` and logic to determine arguments for this method. This will not remove returning the `transition` context when no `model` hook is defined. | ||
|
||
## How we teach this | ||
|
||
Most of this behaviour is lightly documented. Developers often come to this by mistake after some difficult searching. First, we will have to remove this sentence from the [docs](https://guides.emberjs.com/release/routing/defining-your-routes/#toc_dynamic-segments). | ||
|
||
> The first reason is that Routes know how to fetch the right model by default, if you follow the convention. | ||
A direct one to one replacement might look like this. | ||
|
||
```js | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class PostRoute extends Route { | ||
// assuming you have ember-data installed | ||
@service store; | ||
|
||
beforeModel() { | ||
// do stuff | ||
} | ||
|
||
model({ post_id }) { | ||
return this.store.findRecord('post', post_id); | ||
} | ||
|
||
afterModel() { | ||
// do stuff | ||
} | ||
} | ||
``` | ||
|
||
## Alternatives | ||
|
||
- Continue to provide fallback fetching behaviour but ensure no `assert` is called for users that have neither a store nor a `Model` with a `find` method. | ||
|
||
## Open Questions | ||
|
||
## Related links and RFCs | ||
- [Deprecate defaultStore located at `Route.store`](https://github.com/emberjs/rfcs/issues/377) | ||
- [Pre-RFC: Deprecate implicit injections (owner.inject)](https://github.com/emberjs/rfcs/issues/508) | ||
- [Deprecate implicit record loading in routes](https://github.com/emberjs/rfcs/issues/557) |
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
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,59 @@ | ||
--- | ||
stage: accepted | ||
start-date: 2022-01-29 | ||
release-date: Unreleased | ||
release_versions: | ||
teams: | ||
- data | ||
prs: | ||
accepted: https://github.com/emberjs/rfcs/pull/790 | ||
project-link: | ||
suite: | ||
--- | ||
|
||
# EmberData | Deprecate ajax requests | ||
|
||
## Summary | ||
|
||
Deprecates use of `ajax` methods in favor of `fetch` to request API data. | ||
|
||
## Motivation | ||
|
||
Currently, `ember-data` maintains two methods for users to fetch data from their backend - fetching with `jQuery.ajax` and `fetch`. Confusion further exists in the adapters if users implement functionality to change out of the box behaviour. They can override [`ajax`](https://github.com/emberjs/data/blob/e076e0ae71ae6426ca53ad3c5501a0af7ceca883/packages/adapter/addon/rest.ts#L1091-L1126) methods but without a clean interface to operate with, what they really may be doing is overriding how fetch works. | ||
|
||
With Ember 4.0 dropping jQuery, we should take a hard stance on dropping the use of `ajax` in the next major release. | ||
|
||
## Detailed design | ||
|
||
The first step is putting in place a deprecation if an adapter uses `ajax` to make a request. Since `ember-data` switched the default behaviour to use fetch in 4.0, this deprecation will only apply to those who have overrided the default with `useFetch = true` in their adapters. | ||
|
||
Second, we will expose fetch related methods on the adapters that are equivalent in use and flexibility as the current `ajax` options. Note the [`minimum-adapter-interface`](https://github.com/emberjs/data/blob/master/packages/store/addon/-private/ts-interfaces/minimum-adapter-interface.ts) does not assert the method by which a request is made. As a result, how we design and implement these methods should not have an effect on those users who have implemented their own adapter. | ||
|
||
In 5.0, all `ajax` methods and supporting infrastructure will be removed. The list of affected methods includes: | ||
|
||
- ajax | ||
- _ajaxRequest | ||
- _ajax | ||
- ajaxOptions | ||
- _ajaxUrl | ||
|
||
Moreover, we may rename methods not part of the minimum-adapter-interface. Moreover, we expect to implement the following methods with [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch), although could be changed in the actual implementation. | ||
|
||
- fetch | ||
- fetchOptions | ||
- fetchSuccess | ||
- fetchError | ||
- fetchUrl | ||
|
||
## How we teach this | ||
|
||
This is best taught through a deprecation guide. Users using `ajax` will need to install `ember-fetch` or rely on the default global `fetch` API provided by the browser. This has some implications, for example, with how query params are serialized. Users will have to be careful to ensure the behaviour of their API changes with any changes that result from switching to fetch. | ||
|
||
## Drawbacks | ||
|
||
Some user's technology stacks may be entirely dependent on `ajax` for requesting API data. This isn't necessarily an easy switch and may require multiple improvements to various layers to use `fetch`. For those users, we can document how they can still implement their own adapter to use `ajax`. This will involve overriding the existing `fetch` methods. For example, if your API still needs to be serviced with `ajax` to perhaps take advantage of [ajax options](https://api.jquery.com/jquery.ajax/#jQuery-ajax-url-settings) or [ajaxPrefilter](https://api.jquery.com/jquery.ajaxprefilter/), simply override the existing `fetch` methods. The goal of this refactor would be to ensure users who still need to use `ajax` has a happy path to doing so. | ||
|
||
## Alternatives | ||
|
||
- Continue providing and exposing public-ish adapters methods as `ajax`. | ||
- Provide both `fetch` and `ajax` methods together in the adapters. |
Oops, something went wrong.