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 deprecated finder methods on the store. #3490

Merged
merged 1 commit into from
Jul 6, 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
5 changes: 3 additions & 2 deletions packages/ember-data/lib/adapters/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,9 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
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` 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.
Expand Down
175 changes: 6 additions & 169 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,89 +481,27 @@ Store = Service.extend({
@param {Object} options
@return {Promise} promise
*/
find: function(modelName, id, preload) {
find: function(modelName, id, options) {
Ember.assert("You need to pass a type to the store's find method", arguments.length >= 1);
Ember.assert("You may not pass `" + id + "` as id to the store's find method", arguments.length === 1 || !Ember.isNone(id));
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');

if (arguments.length === 1) {
Ember.deprecate('Using store.find(type) has been deprecated. Use store.findAll(type) to retrieve all records for a given type.');
return this.findAll(modelName);
Ember.assert('Using store.find(type) has been removed. Use store.findAll(type) to retrieve all records for a given type.');
}

// We are passed a query instead of an id.
if (Ember.typeOf(id) === 'object') {
Ember.deprecate('Calling store.find() with a query object is deprecated. Use store.query() instead.');
return this.query(modelName, id);
Ember.assert('Calling store.find() with a query object is no longer supported. Use store.query() instead.');
}
var options = deprecatePreload(preload, this.modelFor(modelName), 'find');
return this.findRecord(modelName, coerceId(id), options);
},

/**
This method returns a fresh record for a given type and id combination.

@method fetchById
@deprecated Use [findRecord](#method_findRecord) instead
@param {String} modelName
@param {(String|Integer)} id
@param {Object} options
@return {Promise} promise
*/
fetchById: function(modelName, id, preload) {
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');
var options = deprecatePreload(preload, this.modelFor(modelName), 'fetchById');
Ember.deprecate('Using store.fetchById(type, id) has been deprecated. Use store.findRecord(type, id, { reload: true }) to reload a record for a given type.');
if (this.hasRecordForId(modelName, id)) {
return this.peekRecord(modelName, id).reload();
} else {
return this.findRecord(modelName, id, options);
if (options) {
Ember.assert('Calling store.find(type, id, preload) with a preload object is no longer supported. Use store.findRecord(type, id, { preload: preload }) instead.');
}
},

/**
This method returns a fresh collection from the server, regardless of if there is already records
in the store or not.

@method fetchAll
@deprecated Use [findAll](#method_findAll) instead
@param {String} modelName
@return {Promise} promise
*/
fetchAll: function(modelName) {
Ember.deprecate('Using store.fetchAll(type) has been deprecated. Use store.findAll(type, { reload: true }) to retrieve all records for a given type.');
return this.findAll(modelName, { reload: true });
return this.findRecord(modelName, coerceId(id), options);
},

/**
@method fetch
@param {String} modelName
@param {(String|Integer)} id
@param {Object} preload - optional set of attributes and relationships passed in either as IDs or as actual models
@return {Promise} promise
@deprecated Use [findRecord](#method_findRecord) instead
*/
fetch: function(modelName, id, preload) {
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');
Ember.deprecate('Using store.fetch() has been deprecated. Use store.findRecord for fetching individual records or store.findAll for collections');
return this.findRecord(modelName, id, { reload: true, preload: preload });
},

/**
This method returns a record for a given type and id combination.

@method findById
@private
@param {String} modelName
@param {(String|Integer)} id
@param {Object} options
@return {Promise} promise
*/
findById: function(modelName, id, preload) {
Ember.deprecate('Using store.findById() has been deprecated. Use store.findRecord() to return a record for a given type and id combination.');
var options = deprecatePreload(preload, this.modelFor(modelName), 'findById');
return this.findRecord(modelName, id, options);
},

/**
This method returns a record for a given type and id combination.
Expand Down Expand Up @@ -828,31 +766,6 @@ Store = Service.extend({
}
},

/**
Get a record by a given type and ID without triggering a fetch.

This method will synchronously return the record if it is available in the store,
otherwise it will return `null`. A record is available if it has been fetched earlier, or
pushed manually into the store.

_Note: This is an synchronous method and does not return a promise._

```js
var post = store.getById('post', 1);

post.get('id'); // 1
```

@method getById
@param {String} modelName
@param {String|Integer} id
@return {DS.Model|null} record
*/
getById: function(modelName, id) {
Ember.deprecate('Using store.getById() has been deprecated. Use store.peekRecord to get a record by a given type and ID without triggering a fetch.');
return this.peekRecord(modelName, id);
},

/**
Get a record by a given type and ID without triggering a fetch.

Expand Down Expand Up @@ -1089,28 +1002,6 @@ Store = Service.extend({
return promiseObject(_queryRecord(adapter, this, typeClass, query));
},

/**
This method delegates a query to the adapter. This is the one place where
adapter-level semantics are exposed to the application.

Exposing queries this way seems preferable to creating an abstract query
language for all server-side queries, and then require all adapters to
implement them.

This method returns a promise, which is resolved with a `RecordArray`
once the server returns.

@method query
@param {String} modelName
@param {any} query an opaque query to be used by the adapter
@return {Promise} promise
@deprecated Use `store.query instead`
*/
findQuery: function(modelName, query) {
Ember.deprecate('store#findQuery is deprecated. You should use store#query instead.');
return this.query(modelName, query);
},

/**
`findAll` ask the adapter's `findAll` method to find the records
for the given type, and return a promise that will be resolved
Expand Down Expand Up @@ -1179,34 +1070,6 @@ Store = Service.extend({
set(liveRecordArray, 'isUpdating', false);
},

/**
This method returns a filtered array that contains all of the
known records for a given type in the store.

Note that because it's just a filter, the result will contain any
locally created records of the type, however, it will not make a
request to the backend to retrieve additional records. If you
would like to request all the records from the backend please use
[store.find](#method_find).

Also note that multiple calls to `all` for a given type will always
return the same `RecordArray`.

Example

```javascript
var localPosts = store.all('post');
```

@method all
@param {String} modelName
@return {DS.RecordArray}
*/
all: function(modelName) {
Ember.deprecate('Using store.all() has been deprecated. Use store.peekAll() to get all records by a given type without triggering a fetch.');
return this.peekAll(modelName);
},

/**
This method returns a filtered array that contains all of the
known records for a given type in the store.
Expand Down Expand Up @@ -2360,31 +2223,5 @@ function setupRelationships(store, record, data) {
});
}

function deprecatePreload(preloadOrOptions, type, methodName) {
if (preloadOrOptions) {
var modelProperties = [];
var fields = Ember.get(type, 'fields');
fields.forEach((fieldType, key) => modelProperties.push(key));
var preloadDetected = false;

for (let i = 0, length = modelProperties.length; i < length; i++) {
let key = modelProperties[i];
if (typeof preloadOrOptions[key] !== 'undefined') {
preloadDetected = true;
break;
}
}

if (preloadDetected) {
Ember.deprecate(`Passing a preload argument to \`store.${methodName}\` is deprecated. Please move it to the preload key on the ${methodName} \`options\` argument.`);
var preload = preloadOrOptions;
return {
preload: preload
};
}
}
return preloadOrOptions;
}

export { Store };
export default Store;
17 changes: 2 additions & 15 deletions packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ var Promise = Ember.RSVP.Promise;

export function _find(adapter, store, typeClass, id, internalModel, options) {
var snapshot = internalModel.createSnapshot(options);
var promise;
if (!adapter.findRecord) {
Ember.deprecate('Adapter#find has been deprecated and renamed to `findRecord`.');
promise = adapter.find(store, typeClass, id, snapshot);
} else {
promise = adapter.findRecord(store, typeClass, id, snapshot);
}
var promise = adapter.findRecord(store, typeClass, id, snapshot);
var serializer = serializerForAdapter(store, adapter, internalModel.type.modelName);
var label = "DS: Handle Adapter#find of " + typeClass + " with id: " + id;

Expand Down Expand Up @@ -145,14 +139,7 @@ export function _findAll(adapter, store, typeClass, sinceToken, options) {

export function _query(adapter, store, typeClass, query, recordArray) {
var modelName = typeClass.modelName;
var promise;

if (!adapter.query) {
Ember.deprecate('Adapter#findQuery has been deprecated and renamed to `query`.');
promise = adapter.findQuery(store, typeClass, query, recordArray);
} else {
promise = adapter.query(store, typeClass, query, recordArray);
}
var promise = adapter.query(store, typeClass, query, recordArray);

var serializer = serializerForAdapter(store, adapter, modelName);
var label = "DS: Handle Adapter#findQuery of " + typeClass;
Expand Down
17 changes: 0 additions & 17 deletions packages/ember-data/tests/integration/adapter/find-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ test("It raises an assertion when `undefined` is passed as id (#1705)", function
}, "You may not pass `null` as id to the store's find method");
});

test("store.find(type) is deprecated", function() {
env.registry.register('adapter:person', DS.Adapter.extend({
findAll: function(store, typeClass) {
return [];
}
}));

expectDeprecation(
function() {
run(function() {
store.find('person');
});
},
'Using store.find(type) has been deprecated. Use store.findAll(type) to retrieve all records for a given type.'
);
});

test("store.findAll should trigger a deprecation warning about store.shouldReloadAll", function() {
env.adapter.findAll = function() {
return Ember.RSVP.resolve([]);
Expand Down
13 changes: 1 addition & 12 deletions packages/ember-data/tests/integration/peek-all-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var run = Ember.run;

var Person, store, array, moreArray;

module("integration/peek_all - DS.Store#peekAll()", {
module("integration/peek-all - DS.Store#peekAll()", {
setup: function() {
array = [{ id: 1, name: "Scumbag Dale" }, { id: 2, name: "Scumbag Katz" }];
moreArray = [{ id: 3, name: "Scumbag Bryn" }];
Expand Down Expand Up @@ -53,14 +53,3 @@ test("Calling store.peekAll() after creating a record should return correct data
equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person');
});
});

test("store.all() is deprecated", function() {
expectDeprecation(
function() {
run(function() {
store.all('person');
});
},
'Using store.all() has been deprecated. Use store.peekAll() to get all records by a given type without triggering a fetch.'
);
});
54 changes: 0 additions & 54 deletions packages/ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,6 @@ test("destroying the store correctly cleans everything up", function() {
equal(filterdPeopleWillDestroy.called.length, 1, 'expected filterdPeople.willDestroy to have been called once');
});

module("integration/store - findById() [deprecated]", {
setup: function() {
initializeStore(DS.RESTAdapter.extend());
}
});

test("store.findById() is deprecated", function() {
expectDeprecation(
function() {
run(function() {
store.push('person', { id: 1, name: "Tomster" });
store.findById('person', 1);
});
},
'Using store.findById() has been deprecated. Use store.findRecord() to return a record for a given type and id combination.'
);
});

module("integration/store - fetch", {
setup: function() {
initializeStore(DS.RESTAdapter.extend());
}
});

function ajaxResponse(value) {
var passedUrl, passedVerb, passedHash;
env.adapter.ajax = function(url, verb, hash) {
Expand All @@ -214,22 +190,7 @@ function ajaxResponse(value) {
};
}

test("Using store#fetch is deprecated", function() {
ajaxResponse({
cars: [
{ id: 1, make: 'BMW', model: 'Mini' }
]
});

expectDeprecation(
function() {
run(function() {
store.fetch('car', 1);
});
},
'Using store.fetch() has been deprecated. Use store.findRecord for fetching individual records or store.findAll for collections'
);
});

module("integration/store - findRecord { reload: true }", {
setup: function() {
Expand Down Expand Up @@ -294,21 +255,6 @@ module("integration/store - findAll", {
}
});

test("store#fetchAll() is deprecated", function() {
ajaxResponse({
cars: []
});

expectDeprecation(
function() {
run(function() {
store.fetchAll('car');
});
},
'Using store.fetchAll(type) has been deprecated. Use store.findAll(type, { reload: true }) to retrieve all records for a given type.'
);
});

test("Using store#findAll with no records triggers a query", function() {
expect(2);

Expand Down
Loading