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 21 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 this property in favor of an explicit application adapter fallback.

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)
35 changes: 35 additions & 0 deletions content/ember-data/v3/default-serializer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: ember-data:default-serializers
title: Default serializers usage
until: '4.0.0'
since: '3.12.0'
---
## Default serializer deprecations
### deprecate adapter.defaultSerializer fallback
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. A single `application` serializer can be used a for any model types not requiring custom serialization. To define a type-specific serializer, create an `app/serializers/[type].js` with the following:

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

export default class UserSerializer extends JSONApiSerializer {
/*custom code*/
}
```

Defining a serializer for the entire application can be done by adding the file `app/serializers/application.js` with the following:

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




50 changes: 50 additions & 0 deletions content/ember-data/v3/toJSON.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
id: record.toJSON
title: Record toJSON usage
until: '4.0.0'
since: '3.12.0'
---
## Deprecates the built in `record.toJSON`
Previously users could use [`record.toJSON`](https://github.com/emberjs/data/blob/1be481a4924b2b4316c1cc151a58328c88903dcd/packages/store/addon/-private/system/model/model.js#L620) to get a simple JSON serialization of a record instance by either calling the method directly or using `JSON.stringify(record)`.

This method used the now deprecated `-json` serializer to create this JSON representation of the record instead of the user supplied serializer. In addition to the surprising use of a different serializer, this creates an unnecessary dependency on the `JSONSerializer` for applications that may not otherwise have imported and uses this serializer.

We have deprecated EmberData's own implementation of this method in favor of users implementing their own (or refactoring away).

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';

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();
```