Skip to content

Commit

Permalink
Move snapshot property setting to corresponding constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicEric committed Dec 15, 2015
1 parent 431b65f commit 36b22de
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
13 changes: 2 additions & 11 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import RootState from "ember-data/-private/system/model/states";
import Relationships from "ember-data/-private/system/relationships/state/create";
import Snapshot from "ember-data/-private/system/snapshot";
import EmptyObject from "ember-data/-private/system/empty-object";
import isEnabled from 'ember-data/-private/features';

import {
getOwner
Expand Down Expand Up @@ -243,16 +242,8 @@ InternalModel.prototype = {
@method createSnapshot
@private
*/
createSnapshot(options = {}) {
const snapshot = new Snapshot(this);

snapshot.adapterOptions = options.adapterOptions;

if (isEnabled('ds-finder-include')) {
snapshot.include = options.include;
}

return snapshot;
createSnapshot(options) {
return new Snapshot(this, options);
},

/**
Expand Down
13 changes: 2 additions & 11 deletions addon/-private/system/record-arrays/record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import Ember from 'ember';
import { PromiseArray } from "ember-data/-private/system/promise-proxies";
import SnapshotRecordArray from "ember-data/-private/system/snapshot-record-array";
import isEnabled from 'ember-data/-private/features';

var get = Ember.get;
var set = Ember.set;
Expand Down Expand Up @@ -202,16 +201,8 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
this._super.apply(this, arguments);
},

createSnapshot(options = {}) {
const adapterOptions = options.adapterOptions;
createSnapshot(options) {
const meta = this.get('meta');

const snapshot = new SnapshotRecordArray(this, meta, adapterOptions);

if (isEnabled('ds-finder-include')) {
snapshot.include = options.include;
}

return snapshot;
return new SnapshotRecordArray(this, meta, options);
}
});
10 changes: 8 additions & 2 deletions addon/-private/system/snapshot-record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@module ember-data
*/

import isEnabled from 'ember-data/-private/features';

/**
@class SnapshotRecordArray
@namespace DS
Expand All @@ -10,7 +12,7 @@
@param {Array} snapshots An array of snapshots
@param {Object} meta
*/
export default function SnapshotRecordArray(recordArray, meta, adapterOptions) {
export default function SnapshotRecordArray(recordArray, meta, options = {}) {
/**
An array of snapshots
@private
Expand Down Expand Up @@ -48,7 +50,11 @@ export default function SnapshotRecordArray(recordArray, meta, adapterOptions) {
@property adapterOptions
@type {Object}
*/
this.adapterOptions = adapterOptions;
this.adapterOptions = options.adapterOptions;

if (isEnabled('ds-finder-include')) {
this.include = options.include;
}
}

/**
Expand Down
15 changes: 14 additions & 1 deletion addon/-private/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import Ember from 'ember';
import EmptyObject from "ember-data/-private/system/empty-object";
import isEnabled from 'ember-data/-private/features';

var get = Ember.get;

/**
Expand All @@ -13,7 +15,7 @@ var get = Ember.get;
@constructor
@param {DS.Model} internalModel The model to create a snapshot from
*/
export default function Snapshot(internalModel) {
export default function Snapshot(internalModel, options = {}) {
this._attributes = new EmptyObject();
this._belongsToRelationships = new EmptyObject();
this._belongsToIds = new EmptyObject();
Expand All @@ -29,6 +31,17 @@ export default function Snapshot(internalModel) {
this.type = internalModel.type;
this.modelName = internalModel.type.modelName;

/**
A hash of adapter options
@property adapterOptions
@type {Object}
*/
this.adapterOptions = options.adapterOptions;

if (isEnabled('ds-finder-include')) {
this.include = options.include;
}

this._changedAttributes = record.changedAttributes();
}

Expand Down

0 comments on commit 36b22de

Please sign in to comment.