Skip to content

Commit

Permalink
Merge pull request #3443 from wecc/cleanup-Snapshot
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove Snapshot deprecations
  • Loading branch information
bmac committed Jun 30, 2015
2 parents 0148b13 + 6210041 commit cdaa644
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 225 deletions.
83 changes: 0 additions & 83 deletions packages/ember-data/lib/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@ export default function Snapshot(internalModel) {
this.modelName = internalModel.type.modelName;

this._changedAttributes = record.changedAttributes();

// The following code is here to keep backwards compatibility when accessing
// `constructor` directly.
//
// With snapshots you should use `type` instead of `constructor`.
//
// Remove for Ember Data 1.0.
var callDeprecate = true;

Object.defineProperty(this, 'constructor', {
get: function() {
// Ugly hack since accessing error.stack (done in `Ember.deprecate()`)
// causes the internals of Chrome to access the constructor, which then
// causes an infinite loop if accessed and calls `Ember.deprecate()`
// again.
if (callDeprecate) {
callDeprecate = false;
Ember.deprecate('Usage of `snapshot.constructor` is deprecated, use `snapshot.type` instead.');
callDeprecate = true;
}

return this.type;
}
});
}

Snapshot.prototype = {
Expand Down Expand Up @@ -359,73 +335,14 @@ Snapshot.prototype = {
this.record.eachRelationship(callback, binding);
},

/**
@method get
@param {String} keyName
@return {Object} The property value
@deprecated Use [attr](#method_attr), [belongsTo](#method_belongsTo) or [hasMany](#method_hasMany) instead
*/
get: function(keyName) {
Ember.deprecate('Using DS.Snapshot.get() is deprecated. Use .attr(), .belongsTo() or .hasMany() instead.');

if (keyName === 'id') {
return this.id;
}

if (keyName in this._attributes) {
return this.attr(keyName);
}

var relationship = this._internalModel._relationships.get(keyName);

if (relationship && relationship.relationshipMeta.kind === 'belongsTo') {
return this.belongsTo(keyName);
}
if (relationship && relationship.relationshipMeta.kind === 'hasMany') {
return this.hasMany(keyName);
}

return get(this.record, keyName);
},

/**
@method serialize
@param {Object} options
@return {Object} an object whose values are primitive JSON values only
*/
serialize: function(options) {
return this.record.store.serializerFor(this.modelName).serialize(this, options);
},

/**
@method unknownProperty
@param {String} keyName
@return {Object} The property value
@deprecated Use [attr](#method_attr), [belongsTo](#method_belongsTo) or [hasMany](#method_hasMany) instead
*/
unknownProperty: function(keyName) {
return this.get(keyName);
},

/**
@method _createSnapshot
@private
*/
_createSnapshot: function() {
Ember.deprecate("You called _createSnapshot on what's already a DS.Snapshot. You shouldn't manually create snapshots in your adapter since the store passes snapshots to adapters by default.");
return this;
}
};

Object.defineProperty(Snapshot.prototype, 'typeKey', {
enumerable: false,
get: function() {
Ember.deprecate('Snapshot.typeKey is deprecated. Use snapshot.modelName instead.');
return this.modelName;
},
set: function() {
Ember.assert('Setting snapshot.typeKey is not supported. In addition, Snapshot.typeKey has been deprecated for Snapshot.modelName.');
}
});

export default Snapshot;
142 changes: 0 additions & 142 deletions packages/ember-data/tests/integration/snapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ test("record._createSnapshot() returns a snapshot", function() {
});
});

test("snapshot._createSnapshot() returns a snapshot (self) but is deprecated", function() {
expect(2);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot1 = post._createSnapshot();
var snapshot2;

expectDeprecation(function() {
snapshot2 = snapshot1._createSnapshot();
}, /You called _createSnapshot on what's already a DS.Snapshot. You shouldn't manually create snapshots in your adapter since the store passes snapshots to adapters by default./);

ok(snapshot2 === snapshot1, 'snapshot._createSnapshot() returns self');
});

});

test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", function() {
expect(3);

Expand All @@ -67,27 +50,6 @@ test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", func
});
});

if (Ember.platform.hasPropertyAccessors) {
test("snapshot.constructor is unique and deprecated", function() {
expect(4);

run(function() {
var comment = env.store.push('comment', { id: 1, body: 'This is comment' });
var post = env.store.push('post', { id: 2, title: 'Hello World' });
var commentSnapshot = comment._createSnapshot();
var postSnapshot = post._createSnapshot();

expectDeprecation(function() {
equal(commentSnapshot.constructor.modelName, 'comment', 'constructor.modelName is unique per type');
});

expectDeprecation(function() {
equal(postSnapshot.constructor.modelName, 'post', 'constructor.modelName is unique per type');
});
});
});
}

test("snapshot.attr() does not change when record changes", function() {
expect(2);

Expand Down Expand Up @@ -551,94 +513,6 @@ test("snapshot.hasMany() does not trigger a call to store.scheduleFetch", functi
});
});

test("snapshot.get() is deprecated", function() {
expect(1);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot = post._createSnapshot();

expectDeprecation(function() {
snapshot.get('title');
}, 'Using DS.Snapshot.get() is deprecated. Use .attr(), .belongsTo() or .hasMany() instead.');
});
});

test("snapshot.get() returns id", function() {
expect(2);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot = post._createSnapshot();

expectDeprecation(function() {
equal(snapshot.get('id'), '1', 'snapshot id is correct');
});
});
});

test("snapshot.get() returns attribute", function() {
expect(2);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot = post._createSnapshot();

expectDeprecation(function() {
equal(snapshot.get('title'), 'Hello World', 'snapshot title is correct');
});
});
});

test("snapshot.get() returns belongsTo", function() {
expect(3);

run(function() {
var comment = env.store.push('comment', { id: 1, body: 'This is a comment', post: 2 });
var snapshot = comment._createSnapshot();
var relationship;

expectDeprecation(function() {
relationship = snapshot.get('post');
});

ok(relationship instanceof DS.Snapshot, 'relationship is an instance of DS.Snapshot');
equal(relationship.id, '2', 'relationship id is correct');
});
});

test("snapshot.get() returns hasMany", function() {
expect(3);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
var snapshot = post._createSnapshot();
var relationship;

expectDeprecation(function() {
relationship = snapshot.get('comments');
});

ok(relationship instanceof Array, 'relationship is an instance of Array');
equal(relationship.length, 2, 'relationship has two items');
});
});

test("snapshot.get() proxies property to record unless identified as id, attribute or relationship", function() {
expect(2);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot = post._createSnapshot();

post.set('category', 'Ember.js'); // category is not defined as an DS.attr()

expectDeprecation(function() {
equal(snapshot.get('category'), 'Ember.js', 'snapshot proxies unknown property correctly');
});
});
});

test("snapshot.serialize() serializes itself", function() {
expect(2);

Expand All @@ -652,19 +526,3 @@ test("snapshot.serialize() serializes itself", function() {
deepEqual(snapshot.serialize({ includeId: true }), { id: "1", author: undefined, title: 'Hello World' }, 'serialize takes options');
});
});

if (Ember.platform.hasPropertyAccessors) {
test('snapshot.typeKey is deprecated', function() {
expect(1);

run(function() {
var post = env.store.push('post', { id: 1, title: 'Hello World' });
var snapshot = post._createSnapshot();

expectDeprecation(function() {
return snapshot.typeKey;
});
});

});
}

0 comments on commit cdaa644

Please sign in to comment.