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

Rename and deprecate finders (store.all -> store.peekAll and store.getById -> store.peekRecord) #3209

Merged
merged 2 commits into from
Jun 10, 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: 1 addition & 1 deletion packages/ember-data/lib/system/debug/debug-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default Ember.DataAdapter.extend({
}
}
assert("Cannot find model name. Please upgrade to Ember.js >= 1.13 for Ember Inspector support", !!modelName);
return this.get('store').all(modelName);
return this.get('store').peekAll(modelName);
},

getRecordColumnValues: function(record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default RecordArray.extend({
Example
```javascript
var allPeople = store.all('person');
var allPeople = store.peekAll('person');
allPeople.mapBy('name'); // ["Tom Dale", "Yehuda Katz", "Trek Glowacki"]
var people = store.filter('person', function(person) {
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-data/lib/system/record-arrays/record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
Example
```javascript
var people = store.all('person');
var people = store.peekAll('person');
people.get('isLoaded'); // true
```
Expand All @@ -60,7 +60,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
Example
```javascript
var people = store.all('person');
var people = store.peekAll('person');
people.get('isUpdating'); // false
people.update();
people.get('isUpdating'); // true
Expand Down Expand Up @@ -101,7 +101,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
Example
```javascript
var people = store.all('person');
var people = store.peekAll('person');
people.get('isUpdating'); // false
people.update();
people.get('isUpdating'); // true
Expand Down Expand Up @@ -152,7 +152,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
Example
```javascript
var messages = store.all('message');
var messages = store.peekAll('message');
messages.forEach(function(message) {
message.set('hasBeenSeen', true);
});
Expand Down
59 changes: 56 additions & 3 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ if (!Service) {

Note: When creating a new record using any of the above methods
Ember Data will update `DS.RecordArray`s such as those returned by
`store#all()`, `store#findAll()` or `store#filter()`. This means any
`store#peekAll()`, `store#findAll()` or `store#filter()`. This means any
data bindings or computed properties that depend on the RecordArray
will automatically be synced to include the new or updated record
values.
Expand Down Expand Up @@ -530,7 +530,7 @@ Store = Service.extend({
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');
if (this.hasRecordForId(modelName, id)) {
return this.getById(modelName, id).reload();
return this.peekRecord(modelName, id).reload();
} else {
return this.findRecord(modelName, id, options);
}
Expand Down Expand Up @@ -801,6 +801,31 @@ Store = Service.extend({
@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.

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.peekRecord('post', 1);

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

@method peekRecord
@param {String} modelName
@param {String|Integer} id
@return {DS.Model|null} record
*/
peekRecord: function(modelName, 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 (this.hasRecordForId(modelName, id)) {
return this._internalModelForId(modelName, id).getRecord();
Expand Down Expand Up @@ -1024,7 +1049,7 @@ Store = Service.extend({
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');
var typeClass = this.modelFor(modelName);

return this._fetchAll(typeClass, this.all(modelName));
return this._fetchAll(typeClass, this.peekAll(modelName));
},

/**
Expand Down Expand Up @@ -1080,6 +1105,34 @@ Store = Service.extend({
@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.

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 `peekAll` for a given type will always
return the same `RecordArray`.

Example

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

@method peekAll
@param {String} modelName
@return {DS.RecordArray}
*/
peekAll: function(modelName) {
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');
var typeClass = this.modelFor(modelName);

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 @@ -135,7 +135,7 @@ export function _findAll(adapter, store, typeClass, sinceToken) {
});

store.didUpdateAll(typeClass);
return store.all(modelName);
return store.peekAll(modelName);
}, null, "DS: Extract payload of findAll " + typeClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ test("When all records for a type are requested, records that are already loaded
store.createRecord('person', { name: "Alex MacCaw" });
});

allRecords = store.all('person');
allRecords = store.peekAll('person');

equal(get(allRecords, 'length'), 2, "the record array's length is 2");
equal(allRecords.objectAt(0).get('name'), "Jeremy Ashkenas", "the first item in the record array is Jeremy Ashkenas");
Expand All @@ -118,7 +118,7 @@ test("When all records for a type are requested, records that are created on the
person: Person
});

allRecords = store.all('person');
allRecords = store.peekAll('person');

equal(get(allRecords, 'length'), 0, "precond - the record array's length is zero before any records are loaded");

Expand Down
Loading