Skip to content

Commit

Permalink
Rename & deprecate store.all for store.peekAll
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicEric committed Jun 8, 2015
1 parent f49a20a commit 3d4939b
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 101 deletions.
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
32 changes: 30 additions & 2 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 @@ -546,7 +546,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 @@ -1101,6 +1101,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 @@ -131,7 +131,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
55 changes: 0 additions & 55 deletions packages/ember-data/tests/integration/all-test.js

This file was deleted.

66 changes: 66 additions & 0 deletions packages/ember-data/tests/integration/peek-all-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var get = Ember.get;
var run = Ember.run;

var Person, store, array, moreArray;

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" }];
Person = DS.Model.extend({ name: DS.attr('string') });

store = createStore({ person: Person });
},
teardown: function() {
run(store, 'destroy');
Person = null;
array = null;
}
});

test("store.peekAll('person') should return all records and should update with new ones", function() {
run(function() {
store.pushMany('person', array);
});

var all = store.peekAll('person');
equal(get(all, 'length'), 2);

run(function() {
store.pushMany('person', moreArray);
});

equal(get(all, 'length'), 3);
});

test("Calling store.peekAll() multiple times should update immediately inside the runloop", function() {
expect(3);

Ember.run(function() {
equal(get(store.peekAll('person'), 'length'), 0, 'should initially be empty');
store.createRecord('person', { name: "Tomster" });
equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person');
store.push('person', { id: 1, name: "Tomster's friend" });
equal(get(store.peekAll('person'), 'length'), 2, 'should contain two people');
});
});

test("Calling store.peekAll() after creating a record should return correct data", function() {
expect(1);

Ember.run(function() {
store.createRecord('person', { name: "Tomster" });
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.'
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ test("destroying the store correctly cleans everything up", function() {
equal(adapterPopulatedSummary.called.length, 1);
});

test("Should not filter a store.all() array when a record property is changed", function() {
test("Should not filter a store.peekAll() array when a record property is changed", function() {
var car;

var populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray');
var updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray');

store.all('car');
store.peekAll('car');

run(function() {
car = store.push('car', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test("Collection will resolve save on success", function() {
env.store.createRecord('post', { title: 'World' });
});

var posts = env.store.all('post');
var posts = env.store.peekAll('post');

env.adapter.createRecord = function(store, type, snapshot) {
return Ember.RSVP.resolve({ id: 123 });
Expand All @@ -43,7 +43,7 @@ test("Collection will reject save on error", function() {
env.store.createRecord('post', { title: 'World' });
});

var posts = env.store.all('post');
var posts = env.store.peekAll('post');

env.adapter.createRecord = function(store, type, snapshot) {
return Ember.RSVP.reject();
Expand All @@ -62,7 +62,7 @@ test("Retry is allowed in a failure handler", function() {
env.store.createRecord('post', { title: 'World' });
});

var posts = env.store.all('post');
var posts = env.store.peekAll('post');

var count = 0;

Expand Down Expand Up @@ -94,7 +94,7 @@ test("Collection will reject save on invalid", function() {
env.store.createRecord('post', { title: 'World' });
});

var posts = env.store.all('post');
var posts = env.store.peekAll('post');

env.adapter.createRecord = function(store, type, snapshot) {
return Ember.RSVP.reject({ title: 'invalid' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test("records can be deleted during record array enumeration", function () {
adam = env.store.push('person', { id: 1, name: "Adam Sunderland" });
dave = env.store.push('person', { id: 2, name: "Dave Sunderland" });
});
var all = env.store.all('person');
var all = env.store.peekAll('person');

// pre-condition
equal(all.get('length'), 2, 'expected 2 records');
Expand All @@ -49,7 +49,7 @@ test("when deleted records are rolled back, they are still in their previous rec
jaime = env.store.push('person', { id: 1, name: "Jaime Lannister" });
cersei = env.store.push('person', { id: 2, name: "Cersei Lannister" });
});
var all = env.store.all('person');
var all = env.store.peekAll('person');
var filtered;
run(function() {
filtered = env.store.filter('person', function () {
Expand Down
18 changes: 9 additions & 9 deletions packages/ember-data/tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test("can unload a single record", function () {
adam.unloadRecord();
});

equal(env.store.all('person').get('length'), 0);
equal(env.store.peekAll('person').get('length'), 0);
});

test("can unload all records for a given type", function () {
Expand All @@ -74,8 +74,8 @@ test("can unload all records for a given type", function () {
env.store.unloadAll('person');
});

equal(env.store.all('person').get('length'), 0);
equal(env.store.all('car').get('length'), 1);
equal(env.store.peekAll('person').get('length'), 0);
equal(env.store.peekAll('car').get('length'), 1);
});

test("can unload all records", function () {
Expand All @@ -98,8 +98,8 @@ test("can unload all records", function () {
env.store.unloadAll();
});

equal(env.store.all('person').get('length'), 0);
equal(env.store.all('car').get('length'), 0);
equal(env.store.peekAll('person').get('length'), 0);
equal(env.store.peekAll('car').get('length'), 0);
});

test("Unloading all records for a given type clears saved meta data.", function () {
Expand Down Expand Up @@ -128,20 +128,20 @@ test("removes findAllCache after unloading all records", function () {
});

Ember.run(function() {
env.store.all('person');
env.store.peekAll('person');
env.store.unloadAll('person');
});

equal(env.store.all('person').get('length'), 0);
equal(env.store.peekAll('person').get('length'), 0);
});

test("unloading all records also updates record array from all()", function() {
test("unloading all records also updates record array from peekAll()", function() {
var adam, bob;
run(function() {
adam = env.store.push('person', { id: 1, name: "Adam Sunderland" });
bob = env.store.push('person', { id: 2, name: "Bob Bobson" });
});
var all = env.store.all('person');
var all = env.store.peekAll('person');

equal(all.get('length'), 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ test("Relationship.clear removes all records correctly", function() {

run(function() {
post._internalModel._relationships.get('comments').clear();
var comments = Ember.A(env.store.all('comment'));
var comments = Ember.A(env.store.peekAll('comment'));
deepEqual(comments.mapBy('post'), [null, null, null]);
});

Expand Down
Loading

0 comments on commit 3d4939b

Please sign in to comment.