Skip to content
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-0522 Ember-Data Deprecate default serializers and adapters #436

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cfaa877
RFC-0522 Ember-Data Deprecate default serializers and adapters
Sep 9, 2019
54446da
Update content/ember-data/v3/default-adapter.md
pete-the-pete Sep 11, 2019
e646ce9
adding more details
Sep 11, 2019
2079eb8
Update content/ember-data/v3/default-adapter.md
pete-the-pete Sep 11, 2019
2c4d2ce
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 11, 2019
50c5e26
Adding more docs for toJSON
Sep 12, 2019
c861069
Improving adapter deprecation content
Sep 17, 2019
ab3dd6d
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 17, 2019
6d3b540
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 17, 2019
aec8459
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 17, 2019
90a5734
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 17, 2019
dd24441
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 17, 2019
b933c40
More cleanup to content; fixing javascript syntax and highlighting, r…
Sep 17, 2019
a901fff
backticks and js for default-adapter.md
Sep 17, 2019
6213e3f
Update content/ember-data/v3/toJSON.md
pete-the-pete Sep 18, 2019
ec50503
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 18, 2019
e7d7075
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 18, 2019
602e595
Update content/ember-data/v3/default-adapter.md
pete-the-pete Sep 18, 2019
67d9886
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 18, 2019
588f319
Update content/ember-data/v3/default-serializer.md
pete-the-pete Sep 18, 2019
647b82e
Adding heading for toJSON derprecation
Sep 18, 2019
e889c53
Update content/ember-data/v3/default-adapter.md
pete-the-pete Sep 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions content/ember-data/v3/default-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
id: ember-data:default-adapter
title: Default adapter usage
until: '4.0.0'
since: '3.12.0'
---
## Deprecates both store.defaultAdapter (which defaults to -json-api) and the -json-api adapter fallback behavior

Previously, applications could define the store.adapter property which would be used by defaultAdapter and adapterFor as a fallback for when an adapter was not found by an exact name match.

[RFC 522](https://github.com/emberjs/rfcs/pull/522) Deprecated specifying and using these properties in favor of an explicit application adapter fallback.
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved

If you were not setting this value previously, the following should be sufficient to resolve this deprecation:

create the file app/adapters/application.js with the following:

```js
export { default } from '@ember-data/adapters/json-api';
```


If you were setting the adapter property previously to <adapter-name>, create the file app/adapters/application.js with the following:
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved

```js
export { default } from './<adapter-name>';
```


More information about custom adapters can be found on the [ember.js/guides](https://guides.emberjs.com/release/models/customizing-adapters/) and in the [API DOCs](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fadapter)
33 changes: 33 additions & 0 deletions content/ember-data/v3/default-serializer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
id: ember-data:default-serializers
title: Default serializers usage
until: '4.0.0'
since: '3.12.0'
---
## Default serializer deprecations
### deprecate adapter.defaultSerializer fallbacks
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved
Previously, if no application or type-specific serializer was specified, the store would attempt to lookup a serializer via the `defaultSerializer` property on the type's adapter. This behavior is deprecated in favor of explicitly defining a type-specific serializer or application serializer as described in "clearing these deprecations" below.

### -default serializer fallback in store.serializerFor
Previously, when no type-specific serializer, application serializer, or adapter defaultSerializer had been defined by the app, the `-default` serializer would be used which defaulted to `-json-api`. This behavior is deprecated in favor of explicitly defining an application or type-specific serializer as described below.

## clearing these deprecations
More information about custom serializers can be found in the [Serializer API Docs](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fserializer) or on the [ember.js/guides](https://guides.emberjs.com/release/models/customizing-serializers/#toc_customizing-serializers)

If a specific model type requires custom serialization, a type-specific serializer can be created.. Defining a type-specific serializer will clear the first deprecation, but won't clear both deprecations unless a type-specific serializer is defined for every type of model used in the application. To do this, create an `app/serializers/[type].js` with the following:
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved

```js
import { JSONAPISerializer } from '@ember-data/serializers';

export default class UserSerializer extends JSONApiSerializer { /*custom code*/ };
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved
```

Defining a serializer for the entire application will clear the second deprecation, and can clear both deprecations if the app doesn't require any type-specific serialization. To do this, create an `app/serializers/application.js` with the following:
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved

```js
export { JSONAPISerializer } from '@ember-data/serializers';
```




46 changes: 46 additions & 0 deletions content/ember-data/v3/toJSON.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
id: record.toJSON
title: Record toJSON usage
until: '4.0.0'
since: '3.12.0'
---

Users should avoid calling [`toJSON`](https://github.com/emberjs/data/blob/1be481a4924b2b4316c1cc151a58328c88903dcd/packages/store/addon/-private/system/model/model.js#L620) on a record instance since it uses the now deprecated `-default` serializer to create a JSON representation of a model.
pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved

To clear this deprecation users may call record.serialize() or implement their own toJSON instead. The simplest 1:1 refactor is to import a serializer and define a `toJSON` method that returns the serialized data from the model, but users may want to consider implementing a custom "serialize" method that outputs relevant data.

An example of the simple refactor is below:
### before

```js
//app/models/post.js
import Model from '@ember-data/model';

pete-the-pete marked this conversation as resolved.
Show resolved Hide resolved
export default class Post extends Model {};

//other app code
const record = store.peekRecord('post');
// users the default serializer, will have a deprecation warning
const output = record.toJSON();
```

### after
```js
//app/models/post.js
import Model from '@ember-data/model';
import { JSONAPISerializer } from '@ember-data/serializers';

export default class Post extends Model {
toJSON(options) {
/* Create a JSON object with relevant data by either:
- iterating the attributes / relationships of the record into a POJO
- calling this.serialize and then munge output into the desired shape
*/
}
};

//other app code
const record = store.peekRecord('post');
// users the default serializer
const output = record.toJSON();
```