Skip to content

Commit

Permalink
[DOC] Use native syntax in JSONAPISerializer documentation (#7200)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeAstapov authored and igorT committed Jun 5, 2020
1 parent 4d2ea7d commit 82d6f58
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/serializer/addon/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ import { normalizeModelName } from '@ember-data/store';
```app/models/player.js
import Model, { attr, belongsTo } from '@ember-data/model';
export default Model.extend({
name: attr('string'),
skill: attr('string'),
gamesPlayed: attr('number'),
club: belongsTo('club')
});
export default class Player extends Model {
@attr('string') name;
@attr('string') skill;
@attr('number') gamesPlayed;
@belongsTo('club') club;
}
```
```app/models/club.js
import Model, { attr, hasMany } from '@ember-data/model';
export default Model.extend({
name: attr('string'),
location: attr('string'),
players: hasMany('player')
});
export default class Club extends Model {
@attr('string') name;
@attr('string') location;
@hasMany('player') players;
}
```
```js
Expand Down Expand Up @@ -103,25 +103,25 @@ import { normalizeModelName } from '@ember-data/store';
`extractRelationship`.
```app/serializers/application.js
export default JSONAPISerializer.extend({
export default class ApplicationSerializer extends JSONAPISerializer {
normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
let normalizedDocument = this._super(...arguments);
let normalizedDocument = super.normalizeArrayResponse(...arguments);
// Customize document meta
normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
return normalizedDocument;
},
}
extractRelationship(relationshipHash) {
let normalizedRelationship = this._super(...arguments);
let normalizedRelationship = super.extractRelationship(...arguments);
// Customize relationship meta
normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
return normalizedRelationship;
}
});
}
```
@since 1.13.0
Expand Down Expand Up @@ -413,11 +413,11 @@ const JSONAPISerializer = JSONSerializer.extend({
import JSONAPISerializer from '@ember-data/serializer/json-api';
import { dasherize } from '@ember/string';
export default JSONAPISerializer.extend({
export default class ApplicationSerializer extends JSONAPISerializer {
keyForAttribute(attr, method) {
return dasherize(attr).toUpperCase();
}
});
}
```
@method keyForAttribute
Expand All @@ -444,11 +444,11 @@ const JSONAPISerializer = JSONSerializer.extend({
import JSONAPISerializer from '@ember-data/serializer/json-api';
import { underscore } from '@ember/string';
export default JSONAPISerializer.extend({
export default class ApplicationSerializer extends JSONAPISerializer {
keyForRelationship(key, relationship, method) {
return underscore(key);
}
});
}
```
@method keyForRelationship
@param {String} key
Expand Down

0 comments on commit 82d6f58

Please sign in to comment.