Skip to content

Commit

Permalink
Merge pull request #3440 from wecc/cleanup-RESTSerializer
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove RESTSerializer deprecations
  • Loading branch information
bmac committed Jun 30, 2015
2 parents 6d7ffb0 + ae81c86 commit b6294c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 76 deletions.
69 changes: 2 additions & 67 deletions packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,57 +54,6 @@ var camelize = Ember.String.camelize;
*/
var RESTSerializer = JSONSerializer.extend({

/**
If you want to do normalizations specific to some part of the payload, you
can specify those under `normalizeHash`.
For example, given the following json where the the `IDs` under
`"comments"` are provided as `_id` instead of `id`.
```javascript
{
"post": {
"id": 1,
"title": "Rails is omakase",
"comments": [ 1, 2 ]
},
"comments": [{
"_id": 1,
"body": "FIRST"
}, {
"_id": 2,
"body": "Rails is unagi"
}]
}
```
You use `normalizeHash` to normalize just the comments:
```app/serializers/post.js
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeHash: {
comments: function(hash) {
hash.id = hash._id;
delete hash._id;
return hash;
}
}
});
```
The key under `normalizeHash` is usually just the original key
that was in the original payload. However, key names will be
impacted by any modifications done in the `normalizePayload`
method. The `DS.RESTSerializer`'s default implementation makes no
changes to the payload keys.
@property normalizeHash
@type {Object}
@default undefined
*/

/**
Normalizes a part of the JSON payload returned by
the server. You should override this method, munge the hash
Expand Down Expand Up @@ -374,14 +323,13 @@ var RESTSerializer = JSONSerializer.extend({
@method pushPayload
@param {DS.Store} store
@param {Object} rawPayload
@param {Object} payload
*/
pushPayload: function(store, rawPayload) {
pushPayload: function(store, payload) {
let documentHash = {
data: [],
included: []
};
let payload = this.normalizePayload(rawPayload);

for (var prop in payload) {
var modelName = this.modelNameFromPayloadKey(prop);
Expand Down Expand Up @@ -702,19 +650,6 @@ var RESTSerializer = JSONSerializer.extend({
return camelize(modelName);
},

/**
Deprecated. Use modelNameFromPayloadKey instead
@method typeForRoot
@param {String} modelName
@return {String}
@deprecated
*/
typeForRoot: function(modelName) {
Ember.deprecate("typeForRoot is deprecated. Use modelNameFromPayloadKey instead.");
return this.modelNameFromPayloadKey(modelName);
},

/**
You can use this method to customize how polymorphic objects are serialized.
By default the JSON Serializer creates the key by appending `Type` to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,6 @@ test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload ro
});
});

test('typeForRoot is deprecated', function() {
expect(1);

expectDeprecation(function() {
Ember.Inflector.inflector.uncountable('words');
return env.restSerializer.typeForRoot('multi_words');
});
});

test("normalizeResponse can load secondary records of the same type without affecting the query count", function() {
var jsonHash = {
comments: [{ id: "1", body: "Parent Comment", root: true, children: [2, 3] }],
Expand Down

0 comments on commit b6294c2

Please sign in to comment.