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

Remove the JSONAPI serializer refactor feature flag #3346

Merged
merged 1 commit into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ entry in `config/features.json`.

## Feature Flags

* `ds-new-serializer-api`

Activates the new Serializer API for default serializers.
2 changes: 1 addition & 1 deletion config/features.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ds-new-serializer-api": null

}
6 changes: 3 additions & 3 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
@private
*/
_extractEmbeddedRecords: function(serializer, store, typeClass, partial) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
return _newExtractEmbeddedRecords.apply(this, arguments);
}

Expand Down Expand Up @@ -434,7 +434,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
@private
*/
_extractEmbeddedHasMany: function(store, key, embeddedTypeClass, hash) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
return _newExtractEmbeddedHasMany.apply(this, arguments);
}

Expand Down Expand Up @@ -486,7 +486,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
@private
*/
_extractEmbeddedBelongsTo: function(store, key, embeddedTypeClass, hash) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
return _newExtractEmbeddedBelongsTo.apply(this, arguments);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-data/lib/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export default Serializer.extend({
@return {Object}
*/
normalize: function(typeClass, hash) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
return _newNormalize.apply(this, arguments);
}

Expand Down Expand Up @@ -1495,7 +1495,7 @@ export default Serializer.extend({
@param {Object} payload
*/
extractMeta: function(store, typeClass, payload) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
return _newExtractMeta.apply(this, arguments);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var RESTSerializer = JSONSerializer.extend({
@return {Object}
*/
normalize: function(typeClass, hash, prop) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
_newNormalize.apply(this, arguments);
return this._super(...arguments);
}
Expand Down Expand Up @@ -651,7 +651,7 @@ var RESTSerializer = JSONSerializer.extend({
@param {Object} rawPayload
*/
pushPayload: function(store, rawPayload) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && this.get('isNewSerializerAPI')) {
if (this.get('isNewSerializerAPI')) {
_newPushPayload.apply(this, arguments);
return;
}
Expand Down
5 changes: 0 additions & 5 deletions packages/ember-data/lib/system/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ var Serializer = Ember.Object.extend({
This is only to be used temporarily during the transition from the old
serializer API to the new one.

To activate the new Serializer API you need to enable the feature flag
`ds-new-serializer-api`.

http://guides.emberjs.com/v1.12.0/configuring-ember/feature-flags/

This makes the store and the built-in serializers use the new Serializer API.


Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function _findHasMany(adapter, store, internalModel, link, relationship)
//TODO Use a non record creating push
var records = pushPayload(store, payload);
var recordArray = map(records, function(record) { return record._internalModel; });
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && serializer.get('isNewSerializerAPI')) {
if (serializer.get('isNewSerializerAPI')) {
recordArray.meta = payload.meta;
}
return recordArray;
Expand Down
11 changes: 4 additions & 7 deletions packages/ember-data/lib/system/store/serializer-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ var map = Ember.EnumerableUtils.map;
/**
This is a helper method that always returns a JSON-API Document.

If the feature flag `ds-new-serializer-api` is enabled and the current serializer
has `isNewSerializerAPI` set to `true` this helper calls `normalizeResponse`
instead of `extract`.
If the current serializer has `isNewSerializerAPI` set to `true`
this helper calls `normalizeResponse` instead of `extract`.

All the built-in serializers get `isNewSerializerAPI` set to `true` automatically
if the feature flag is enabled.
Expand All @@ -21,12 +20,10 @@ var map = Ember.EnumerableUtils.map;
@return {Object} JSON-API Document
*/
export function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api') && serializer.get('isNewSerializerAPI')) {
if (serializer.get('isNewSerializerAPI')) {
return serializer.normalizeResponse(store, modelClass, payload, id, requestType);
} else {
if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
Ember.deprecate('Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead.');
}
Ember.deprecate('Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead.');
let serializerPayload = serializer.extract(store, modelClass, payload, id, requestType);
return _normalizeSerializerPayload(modelClass, serializerPayload);
}
Expand Down
139 changes: 68 additions & 71 deletions packages/ember-data/tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,97 +1446,94 @@ test("Model's belongsTo relationship should be created during 'get' method", fun
});
});

if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {

test("metadata is accessible when pushed as a meta property for a relationship", function() {
expect(1);
var book;
env.adapter.findHasMany = function() {
return resolve({});
};
test("metadata is accessible when pushed as a meta property for a relationship", function() {
expect(1);
var book;
env.adapter.findHasMany = function() {
return resolve({});
};

run(function() {
book = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', meta: { chapters: 'the lefkada sea' }, links: { chapters: '/chapters' } });
});
run(function() {
book = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', meta: { chapters: 'the lefkada sea' }, links: { chapters: '/chapters' } });
});

run(function() {
equal(book._internalModel._relationships.get('chapters').meta, 'the lefkada sea', 'meta is there');
});
run(function() {
equal(book._internalModel._relationships.get('chapters').meta, 'the lefkada sea', 'meta is there');
});
});

test("metadata is accessible when return from a fetchLink", function() {
expect(1);
env.registry.register('serializer:application', DS.RESTSerializer.extend({ isNewSerializerAPI: true }));
test("metadata is accessible when return from a fetchLink", function() {
expect(1);
env.registry.register('serializer:application', DS.RESTSerializer.extend({ isNewSerializerAPI: true }));

env.adapter.findHasMany = function() {
return resolve({
meta: {
foo: 'bar'
},
chapters: [
{ id: '2' },
{ id: '3' }
]
});
};
env.adapter.findHasMany = function() {
return resolve({
meta: {
foo: 'bar'
},
chapters: [
{ id: '2' },
{ id: '3' }
]
});
};

var book;
var book;

run(function() {
book = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', links: { chapters: '/chapters' } });
});
run(function() {
book = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', links: { chapters: '/chapters' } });
});

run(function() {
book.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(get(meta, 'foo'), 'bar', 'metadata is available');
});
run(function() {
book.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(get(meta, 'foo'), 'bar', 'metadata is available');
});
});
});

test("metadata should be reset between requests", function() {
var counter = 0;
env.registry.register('serializer:application', DS.RESTSerializer.extend({ isNewSerializerAPI: true }));
test("metadata should be reset between requests", function() {
var counter = 0;
env.registry.register('serializer:application', DS.RESTSerializer.extend({ isNewSerializerAPI: true }));

env.adapter.findHasMany = function() {
var data = {
meta: {
foo: 'bar'
},
chapters: [
{ id: '2' },
{ id: '3' }
]
};
env.adapter.findHasMany = function() {
var data = {
meta: {
foo: 'bar'
},
chapters: [
{ id: '2' },
{ id: '3' }
]
};

ok(true, 'findHasMany should be called twice');
ok(true, 'findHasMany should be called twice');

if (counter === 1) {
delete data.meta;
}
if (counter === 1) {
delete data.meta;
}

counter++;
counter++;

return resolve(data);
};
return resolve(data);
};

var book1, book2;
var book1, book2;

run(function() {
book1 = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', links: { chapters: 'chapters' } });
book2 = env.store.push('book', { id: 2, title: 'Another book title', links: { chapters: 'chapters' } });
});
run(function() {
book1 = env.store.push('book', { id: 1, title: 'Sailing the Seven Seas', links: { chapters: 'chapters' } });
book2 = env.store.push('book', { id: 2, title: 'Another book title', links: { chapters: 'chapters' } });
});

run(function() {
book1.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(get(meta, 'foo'), 'bar', 'metadata should available');
run(function() {
book1.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(get(meta, 'foo'), 'bar', 'metadata should available');

book2.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(meta, undefined, 'metadata should not be available');
});
book2.get('chapters').then(function(chapters) {
var meta = chapters.get('meta');
equal(meta, undefined, 'metadata should not be available');
});
});
});
}
});
Loading