Permalink
Browse files

Changes `json` to `data`

See BREAKING_CHANGES.md for more information
  • Loading branch information...
Addepairing Station Addepairing Station
Addepairing Station authored and Addepairing Station committed Nov 13, 2012
1 parent 4440c82 commit 03739a7783de33b1ab1a89f3ecef236d7d3ba064
View
@@ -35,7 +35,42 @@ App.Store = DS.Store.create({
This will remove the exception about changes before revision 2. You will
receive another warning if there is another change.
# Revision 7
## Revision 8
### Making Data Format-Agnostic
Previously, many areas of Ember Data assumed that data exchanged with
the adapter was represented in JSON form. Many of the serializer APIs
cemented this bias by including JSON in method names.
While we anticipate that most Ember.js applications will continue to use
JSON as the primary mechanism for data interchange with a server, we
also want to support innovation in how data is exchanged.
For example, MongoDB can exchange data as BSON--a binary encoded
serialization of JSON. Or, if you are writing a data-heavy application,
we want you to be free to transmit data to the client in whatever form
is most efficient. Now that mainstream browsers support JavaScript
`Blob` objects and `TypedArray`s, we anticipate this use case will
become more and more common.
To that end, we have made two changes:
1. Any information that the store needs from data provided by the
adapter is interpreted via the serializer. For example, instead of
asking for the ID of a data hash via `data.id`, the store will call the
adapter's `extractId` method. This change should not affect
applications.
2. Any methods that contained the term `JSON` have been replaced with
versions that use `Data`. For example,
`DS.Serializer`'s `toJSON` method has been renamed to `toData`.
Similarly, the `transformValueFromJSON` method has been renamed to
`transformValueFromData`. This change should only affect applications
that use customized serializers, or were calling `toJSON` on records.
Because only names and not semantics have changed, this should be a
quick find and replace to bring your app up-to-date.
## Revision 7
### Acknowledging Relationships
@@ -97,7 +132,7 @@ the relationship as saved once the server has
acknowledged the entity.
# Revision 6
## Revision 6
### String-normalized IDs
@@ -27,7 +27,7 @@ DS.FixtureAdapter = DS.Adapter.extend({
Implement this method in order to provide provide json for CRUD methods
*/
mockJSON: function(type, record) {
return this.toJSON(record, { includeId: true });
return this.toData(record, { includeId: true });
},
/*
@@ -20,7 +20,7 @@ DS.RESTAdapter = DS.Adapter.extend({
var root = this.rootForType(type);
var data = {};
data[root] = this.toJSON(record, { includeId: true });
data[root] = this.toData(record, { includeId: true });
this.ajax(this.buildURL(root), "POST", {
data: data,
@@ -67,7 +67,7 @@ DS.RESTAdapter = DS.Adapter.extend({
var data = {};
data[plural] = [];
records.forEach(function(record) {
data[plural].push(this.toJSON(record, { includeId: true }));
data[plural].push(this.toData(record, { includeId: true }));
}, this);
this.ajax(this.buildURL(root), "POST", {
@@ -91,7 +91,7 @@ DS.RESTAdapter = DS.Adapter.extend({
var root = this.rootForType(type);
var data = {};
data[root] = this.toJSON(record);
data[root] = this.toData(record);
this.ajax(this.buildURL(root, id), "PUT", {
data: data,
@@ -120,7 +120,7 @@ DS.RESTAdapter = DS.Adapter.extend({
var data = {};
data[plural] = [];
records.forEach(function(record) {
data[plural].push(this.toJSON(record, { includeId: true }));
data[plural].push(this.toData(record, { includeId: true }));
}, this);
this.ajax(this.buildURL(root, "bulk"), "PUT", {
@@ -1,28 +1,28 @@
DS.Transforms = Ember.Object.extend({
string: {
fromJSON: function(serialized) {
fromData: function(serialized) {
return Ember.none(serialized) ? null : String(serialized);
},
toJSON: function(deserialized) {
toData: function(deserialized) {
return Ember.none(deserialized) ? null : String(deserialized);
}
},
number: {
fromJSON: function(serialized) {
fromData: function(serialized) {
return Ember.none(serialized) ? null : Number(serialized);
},
toJSON: function(deserialized) {
toData: function(deserialized) {
return Ember.none(deserialized) ? null : Number(deserialized);
}
},
// Handles the following boolean inputs:
// "TrUe", "t", "f", "FALSE", 0, (non-zero), or boolean true/false
'boolean': {
fromJSON: function(serialized) {
fromData: function(serialized) {
var type = typeof serialized;
if (type === "boolean") {
@@ -36,13 +36,13 @@ DS.Transforms = Ember.Object.extend({
}
},
toJSON: function(deserialized) {
toData: function(deserialized) {
return Boolean(deserialized);
}
},
date: {
fromJSON: function(serialized) {
fromData: function(serialized) {
var type = typeof serialized;
if (type === "string" || type === "number") {
@@ -61,7 +61,7 @@ DS.Transforms = Ember.Object.extend({
}
},
toJSON: function(date) {
toData: function(date) {
if (date instanceof Date) {
var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
@@ -92,4 +92,4 @@ DS.Transforms = Ember.Object.extend({
}
}
}
});
});
@@ -1,3 +1,3 @@
window.DS = Ember.Namespace.create({
CURRENT_API_REVISION: 7
CURRENT_API_REVISION: 8
});
@@ -123,7 +123,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, {
url = url.fmt(id);
jQuery.getJSON(url, function(data) {
// data is a Hash of key/value pairs. If your server returns a
// data is a hash of key/value pairs. If your server returns a
// root, simply do something like:
// store.load(type, id, data.person)
store.load(type, id, data);
@@ -159,56 +159,56 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, {
*/
generateIdForRecord: null,
materialize: function(record, hash) {
get(this, 'serializer').materializeFromJSON(record, hash);
materialize: function(record, data) {
get(this, 'serializer').materializeFromData(record, data);
},
toJSON: function(record, options) {
return get(this, 'serializer').toJSON(record, options);
toData: function(record, options) {
return get(this, 'serializer').toData(record, options);
},
extractId: function(type, hash) {
return get(this, 'serializer').extractId(type, hash);
extractId: function(type, data) {
return get(this, 'serializer').extractId(type, data);
},
extractEmbeddedData: function(store, type, hash) {
extractEmbeddedData: function(store, type, data) {
var serializer = get(this, 'serializer');
type.eachAssociation(function(name, association) {
var hashesToLoad, hashToLoad, typeToLoad;
var dataListToLoad, dataToLoad, typeToLoad;
if (association.kind === 'hasMany') {
this._extractEmbeddedHasMany(store, serializer, type, hash, association);
this._extractEmbeddedHasMany(store, serializer, type, data, association);
} else if (association.kind === 'belongsTo') {
this._extractEmbeddedBelongsTo(store, serializer, type, hash, association);
this._extractEmbeddedBelongsTo(store, serializer, type, data, association);
}
}, this);
},
_extractEmbeddedHasMany: function(store, serializer, type, hash, association) {
var hashesToLoad = serializer._extractEmbeddedHasMany(type, hash, association.key),
_extractEmbeddedHasMany: function(store, serializer, type, data, association) {
var dataListToLoad = serializer._extractEmbeddedHasMany(type, data, association.key),
typeToLoad = association.type;
if (hashesToLoad) {
if (dataListToLoad) {
var ids = [];
for (var i=0, l=hashesToLoad.length; i<l; i++) {
var hashToLoad = hashesToLoad[i];
ids.push(store.adapterForType(typeToLoad).extractId(typeToLoad, hashToLoad));
for (var i=0, l=dataListToLoad.length; i<l; i++) {
var dataToLoad = dataListToLoad[i];
ids.push(store.adapterForType(typeToLoad).extractId(typeToLoad, dataToLoad));
}
serializer.replaceEmbeddedHasMany(type, hash, association.key, ids);
store.loadMany(association.type, hashesToLoad);
serializer.replaceEmbeddedHasMany(type, data, association.key, ids);
store.loadMany(association.type, dataListToLoad);
}
},
_extractEmbeddedBelongsTo: function(store, serializer, type, hash, association) {
var hashToLoad = serializer._extractEmbeddedBelongsTo(type, hash, association.key),
_extractEmbeddedBelongsTo: function(store, serializer, type, data, association) {
var dataToLoad = serializer._extractEmbeddedBelongsTo(type, data, association.key),
typeToLoad = association.type;
if (hashToLoad) {
var id = store.adapterForType(typeToLoad).extractId(typeToLoad, hashToLoad);
serializer.replaceEmbeddedBelongsTo(type, hash, association.key, id);
store.load(association.type, hashToLoad);
if (dataToLoad) {
var id = store.adapterForType(typeToLoad).extractId(typeToLoad, dataToLoad);
serializer.replaceEmbeddedBelongsTo(type, data, association.key, id);
store.load(association.type, dataToLoad);
}
},
@@ -32,9 +32,9 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
@param {Object} options
@returns {Object} an object whose values are primitive JSON values only
*/
toJSON: function(options) {
toData: function(options) {
var store = get(this, 'store');
return store.toJSON(this, options);
return store.toData(this, options);
},
didLoad: Ember.K,
@@ -127,7 +127,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
updateRecordArrays: function() {
var store = get(this, 'store');
if (store) {
store.hashWasUpdated(this.constructor, get(this, 'clientId'), this);
store.dataWasUpdated(this.constructor, get(this, 'clientId'), this);
}
},
Oops, something went wrong.

0 comments on commit 03739a7

Please sign in to comment.