Skip to content

Commit

Permalink
Rename adapter and serializer methods to match the new store methods
Browse files Browse the repository at this point in the history
Adapter#find -> Adapter#findRecord and Adapter#findQuery -> Adapter#query
BuildURLMixin#urlForFind -> BuildURLMixin#urlForFindRecord and BuildURLMixin#urlForFindQuery -> BuildURLMixin#urlForQuery
Serializer#extractFind -> Serializer#extractFindRecord and Serializer#findQuery -> Serializer#extractQuery
  • Loading branch information
bmac committed Jun 11, 2015
1 parent d4f6050 commit 3e8c9ab
Show file tree
Hide file tree
Showing 35 changed files with 490 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
var json;

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'findRecord');
});

deepEqual(json, {
Expand Down Expand Up @@ -96,7 +96,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
var json;

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'findRecord');
});

deepEqual(json, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {

var json;
run(function() {
json = env.amsSerializer.normalizeSingleResponse(env.store, HomePlanet, json_hash, '1', 'find');
json = env.amsSerializer.normalizeSingleResponse(env.store, HomePlanet, json_hash, '1', 'findRecord');
});

deepEqual(json, {
Expand Down Expand Up @@ -212,7 +212,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
var json;

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'findRecord');
});

deepEqual(json, {
Expand Down Expand Up @@ -253,7 +253,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
var json;

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'findRecord');
});

deepEqual(json, {
Expand Down Expand Up @@ -287,7 +287,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
};

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json, '1', 'findRecord');
});

deepEqual(json, {
Expand Down Expand Up @@ -316,7 +316,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
};

run(function() {
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'findRecord');
});

deepEqual(json, {
Expand All @@ -338,7 +338,7 @@ if (Ember.FEATURES.isEnabled('ds-new-serializer-api')) {
};

run(function () {
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'find');
json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'findRecord');
});

deepEqual(json, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ test("extractSingle", function() {
});

run(function() {
env.store.find('super-villain', 1).then(function(minion) {
env.store.findRecord('super-villain', 1).then(function(minion) {
equal(minion.get('firstName'), "Tom");
});
});
Expand All @@ -182,7 +182,7 @@ test("extractArray", function() {
}]);

run(function() {
env.store.find('super-villain', 1).then(function(minion) {
env.store.findRecord('super-villain', 1).then(function(minion) {
equal(minion.get('firstName'), "Tom");
});
});
Expand Down
59 changes: 49 additions & 10 deletions packages/ember-data/lib/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var get = Ember.get;
```javascript
export default DS.Adapter.extend(BuildURLMixin, {
find: function(store, type, id, snapshot) {
var url = this.buildURL(type.modelName, id, snapshot, 'find');
findRecord: function(store, type, id, snapshot) {
var url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
return this.ajax(url, 'GET');
}
});
Expand All @@ -27,7 +27,7 @@ var get = Ember.get;
@class BuildURLMixin
@namespace DS
*/
export default Ember.Mixin.create({
var BuildURLMixin = Ember.Mixin.create({
/**
Builds a URL for a given type and optional ID.
Expand All @@ -46,17 +46,17 @@ export default Ember.Mixin.create({
@param {(String|Array|Object)} id single id or array of ids or query
@param {(DS.Snapshot|Array)} snapshot single snapshot or array of snapshots
@param {String} requestType
@param {Object} query object of query parameters to send for findQuery requests.
@param {Object} query object of query parameters to send for query requests.
@return {String} url
*/
buildURL: function(modelName, id, snapshot, requestType, query) {
switch (requestType) {
case 'find':
return this.urlForFind(id, modelName, snapshot);
case 'findRecord':
return this.urlForFindRecord(id, modelName, snapshot);
case 'findAll':
return this.urlForFindAll(modelName);
case 'findQuery':
return this.urlForFindQuery(query, modelName);
case 'query':
return this.urlForQuery(query, modelName);
case 'findMany':
return this.urlForFindMany(id, modelName, snapshot);
case 'findHasMany':
Expand Down Expand Up @@ -109,8 +109,22 @@ export default Ember.Mixin.create({
* @param {String} modelName
* @param {DS.Snapshot} snapshot
* @return {String} url
* @deprecated Use [urlForFindRecord](#method_urlForFindRecord) instead
*/
urlForFind: function(id, modelName, snapshot) {
urlForFind: urlForFind,

/**
* @method urlForFind
* @param {String} id
* @param {String} modelName
* @param {DS.Snapshot} snapshot
* @return {String} url
*/
urlForFindRecord: function(id, modelName, snapshot) {
if (this.urlForFind !== urlForFind) {
Ember.deprecate('BuildURLMixin#urlForFind has been deprecated and renamed to `urlForFindRecord`.');
return this.urlForFind(id, modelName, snapshot);
}
return this._buildURL(modelName, id);
},

Expand All @@ -128,8 +142,21 @@ export default Ember.Mixin.create({
* @param {Object} query
* @param {String} modelName
* @return {String} url
* @deprecated Use [urlForQuery](#method_urlForQuery) instead
*/
urlForFindQuery: function(query, modelName) {
urlForFindQuery: urlForFindQuery,

/**
* @method urlForQuery
* @param {Object} query
* @param {String} modelName
* @return {String} url
*/
urlForQuery: function(query, modelName) {
if (this.urlForFindQuery !== urlForFindQuery) {
Ember.deprecate('BuildURLMixin#urlForFind has been deprecated and renamed to `urlForFindQuery`.');
return this.urlForFindQuery(query, modelName);
}
return this._buildURL(modelName);
},

Expand Down Expand Up @@ -270,3 +297,15 @@ export default Ember.Mixin.create({
return Ember.String.pluralize(camelized);
}
});

function urlForFind(id, modelName, snapshot) {
Ember.deprecate('BuildURLMixin#urlForFind has been deprecated and renamed to `urlForFindRecord`.');
return this._buildURL(modelName, id);
}

function urlForFindQuery(query, modelName) {
Ember.deprecate('BuildURLMixin#urlForFindQuery has been deprecated and renamed to `urlForQuery`.');
return this._buildURL(modelName);
}

export default BuildURLMixin;
66 changes: 60 additions & 6 deletions packages/ember-data/lib/adapters/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ var RestAdapter = Adapter.extend(BuildURLMixin, {
relationships accessed within the same runloop. If you set `coalesceFindRequests: true`
```javascript
store.find('comment', 1);
store.find('comment', 2);
store.findRecord('comment', 1);
store.findRecord('comment', 2);
```
will also send a request to: `GET /comments?ids[]=1&ids[]=2`
Expand Down Expand Up @@ -346,25 +346,44 @@ var RestAdapter = Adapter.extend(BuildURLMixin, {
@property headers
@type {Object}
*/

/**
@method findRecord
@param {DS.Store} store
@param {DS.Model} type
@param {String} id
@param {DS.Snapshot} snapshot
@return {Promise} promise
@deprecated Use [findRecord](#method_findRecord) instead
*/
find: function(store, type, id, snapshot) {
Ember.deprecate('RestAdapter#find has been deprecated and renamed to `findRecord`.');
return this.ajax(this.buildURL(type.modelName, id, snapshot, 'find'), 'GET');
},

/**
Called by the store in order to fetch the JSON for a given
type and ID.
The `find` method makes an Ajax request to a URL computed by `buildURL`, and returns a
promise for the resulting payload.
The `findRecord` method makes an Ajax request to a URL computed by
`buildURL`, and returns a promise for the resulting payload.
This method performs an HTTP `GET` request with the id provided as part of the query string.
@method find
@method findRecord
@param {DS.Store} store
@param {DS.Model} type
@param {String} id
@param {DS.Snapshot} snapshot
@return {Promise} promise
*/
find: function(store, type, id, snapshot) {
findRecord: function(store, type, id, snapshot) {
var find = RestAdapter.prototype.find;
if (find !== this.find) {
Ember.deprecate('RestAdapter#find has been deprecated and renamed to `findRecord`.');
return this.find(store, type, id, snapshot);
}
return this.ajax(this.buildURL(type.modelName, id, snapshot, 'find'), 'GET');
},

Expand Down Expand Up @@ -410,8 +429,43 @@ var RestAdapter = Adapter.extend(BuildURLMixin, {
@param {DS.Model} type
@param {Object} query
@return {Promise} promise
@deprecated Use [query](#method_query) instead
*/
findQuery: function(store, type, query) {
Ember.deprecate('RestAdapter#findQuery has been deprecated and renamed to `query`.');
var url = this.buildURL(type.modelName, null, null, 'findQuery', query);

if (this.sortQueryParams) {
query = this.sortQueryParams(query);
}

return this.ajax(url, 'GET', { data: query });
},

/**
Called by the store in order to fetch a JSON array for
the records that match a particular query.
The `findQuery` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
promise for the resulting payload.
The `query` argument is a simple JavaScript object that will be passed directly
to the server as parameters.
@private
@method query
@param {DS.Store} store
@param {DS.Model} type
@param {Object} query
@return {Promise} promise
*/
query: function(store, type, query) {
var findQuery = RestAdapter.prototype.findQuery;
if (findQuery !== this.findQuery) {
Ember.deprecate('RestAdapter#findQuery has been deprecated and renamed to `query`.');
return this.findQuery(store, type, query);
}

var url = this.buildURL(type.modelName, null, null, 'findQuery', query);

if (this.sortQueryParams) {
Expand Down
Loading

0 comments on commit 3e8c9ab

Please sign in to comment.