Skip to content

Commit

Permalink
Add a SnapshotRecordArray object used for passing snapshots, meta and…
Browse files Browse the repository at this point in the history
… adapterOptions to the adapter.
  • Loading branch information
bmac committed Jun 12, 2015
1 parent 43a48a3 commit f260bdc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
34 changes: 34 additions & 0 deletions packages/ember-data/lib/system/snapshot-record-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
@module ember-data
*/

/**
@class SnapshotRecordArray
@namespace DS
@private
@constructor
@param {Array} snapshots An array of snapshots
@param {Object} meta
*/
function SnapshotRecordArray(snapshots, meta, adapterOptions) {
this.snapshots = snapshots;
this.length = snapshots.length;
this.meta = meta;
this.adapterOptions = adapterOptions;
}

/**
@method fromRecordArray
@private
@static
@param {DS.RecordArray} recordArray
@param {Object} adapterOptions
@return SnapshotRecordArray
*/
SnapshotRecordArray.fromRecordArray = function(recordArray, adapterOptions) {
var meta = recordArray.get('meta');
var snapshots = recordArray.invoke('createSnapshot');
return new SnapshotRecordArray(snapshots, meta, adapterOptions);
};

export default SnapshotRecordArray;
5 changes: 4 additions & 1 deletion packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
serializerForAdapter
} from "ember-data/system/store/serializers";

import SnapshotRecordArray from "ember-data/system/snapshot-record-array";

var Promise = Ember.RSVP.Promise;
var map = Ember.EnumerableUtils.map;

Expand Down Expand Up @@ -121,8 +123,9 @@ export function _findBelongsTo(adapter, store, internalModel, link, relationship

export function _findAll(adapter, store, typeClass, sinceToken, options) {
var adapterOptions = options && options.adapterOptions;
var promise = adapter.findAll(store, typeClass, sinceToken, adapterOptions);
var modelName = typeClass.modelName;
var snapshotArray = SnapshotRecordArray.fromRecordArray(store.peekAll(modelName), adapterOptions);
var promise = adapter.findAll(store, typeClass, sinceToken, snapshotArray);
var serializer = serializerForAdapter(store, adapter, modelName);
var label = "DS: Handle Adapter#findAll of " + typeClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ test("findRecord should pass adapterOptions to the find method", function() {
test("findAll should pass adapterOptions to the findAll method", function() {
expect(1);

env.adapter.findAll = async(function(store, type, sinceToken, adapterOptions) {
env.adapter.findAll = async(function(store, type, sinceToken, arraySnapshot) {
var adapterOptions = arraySnapshot.adapterOptions;
deepEqual(adapterOptions, { query: { embed: true } });
return Ember.RSVP.resolve([{ id: 1 }]);
});
Expand Down

0 comments on commit f260bdc

Please sign in to comment.