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

[FEATURE ds-rollback-attribute] rename ds-reset-attribute #4685

Merged
merged 1 commit into from
Nov 30, 2016
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
8 changes: 4 additions & 4 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ entry in `config/features.json`.
Adds public method for `shouldSerializeHasMany`, used to determine if a
`hasMany` relationship can be serialized.

- `ds-reset-attribute` [#4246](https://github.com/emberjs/data/pull/4246)
- `ds-rollback-attribute` [#4246](https://github.com/emberjs/data/pull/4246)

Adds a `resetAttribute` method to models. Similar to `rollbackAttributes`,
Adds a `rollbackAttribute` method to models. Similar to `rollbackAttributes`,
but for only a single attribute.

```js
Expand All @@ -124,10 +124,10 @@ entry in `config/features.json`.
lastName: 'Katz'
});

tom.resetAttribute('firstName') // { firstName: 'Tom', lastName: 'Katz' }
tom.rollbackAttribute('firstName') // { firstName: 'Tom', lastName: 'Katz' }
tom.get('hasDirtyAttributes') // true

tom.resetAttribute('lastName') // { firstName: 'Tom', lastName: 'Dale' }
tom.rollbackAttribute('lastName') // { firstName: 'Tom', lastName: 'Dale' }
tom.get('hasDirtyAttributes') // false
```

Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ export default class InternalModel {
}
}

if (isEnabled('ds-reset-attribute')) {
if (isEnabled('ds-rollback-attribute')) {
/*
Returns the latest truth for an attribute - the canonical value, or the
in-flight value.
Expand Down
8 changes: 4 additions & 4 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ if (Ember.setOwner) {
});
}

if (isEnabled('ds-reset-attribute')) {
if (isEnabled('ds-rollback-attribute')) {
Model.reopen({
/**
Discards any unsaved changes to the given attribute.
Expand All @@ -1049,13 +1049,13 @@ if (isEnabled('ds-reset-attribute')) {
record.get('name'); // 'Untitled Document'
record.set('name', 'Doc 1');
record.get('name'); // 'Doc 1'
record.resetAttribute('name');
record.rollbackAttribute('name');
record.get('name'); // 'Untitled Document'
```

@method resetAttribute
@method rollbackAttribute
*/
resetAttribute(attributeName) {
rollbackAttribute(attributeName) {
if (attributeName in this._internalModel._attributes) {
this.set(attributeName, this._internalModel.lastAcknowledgedValue(attributeName));
}
Expand Down
2 changes: 1 addition & 1 deletion config/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ds-overhaul-references": null,
"ds-payload-type-hooks": null,
"ds-check-should-serialize-relationships": null,
"ds-reset-attribute": null,
"ds-rollback-attribute": null,
"ds-serialize-id": null,
"ds-deprecate-store-serialize": true
}
22 changes: 11 additions & 11 deletions tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ test("changedAttributes() works while the record is being updated", function(ass
});
});

if (isEnabled('ds-reset-attribute')) {
test("resetAttribute() reverts a single attribute to its canonical value", function(assert) {
if (isEnabled('ds-rollback-attribute')) {
test("rollbackAttribute() reverts a single attribute to its canonical value", function(assert) {
assert.expect(5);

run(function() {
Expand All @@ -452,14 +452,14 @@ if (isEnabled('ds-reset-attribute')) {
isDrugAddict: false
});
assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value");
person.resetAttribute('isDrugAddict');
person.rollbackAttribute('isDrugAddict');
assert.equal(person.get('isDrugAddict'), true, "The specified attribute is rolled back");
assert.equal(person.get('name'), 'Piper', "Unspecified attributes are not rolled back");
assert.equal(person.get('hasDirtyAttributes'), true, "record with changed attributes is still dirty");
});
});

test("calling resetAttribute() on an unmodified property has no effect", function(assert) {
test("calling rollbackAttribute() on an unmodified property has no effect", function(assert) {
assert.expect(5);

run(function() {
Expand All @@ -479,14 +479,14 @@ if (isEnabled('ds-reset-attribute')) {
assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty");
person.set('name', 'Piper');
assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value");
person.resetAttribute('isDrugAddict');
person.rollbackAttribute('isDrugAddict');
assert.equal(person.get('isDrugAddict'), true, "The specified attribute does not change value");
assert.equal(person.get('name'), 'Piper', "Unspecified attributes are not rolled back");
assert.equal(person.get('hasDirtyAttributes'), true, "record with changed attributes is still dirty");
});
});

test("Rolling back the final value with resetAttribute() causes the record to become clean again", function(assert) {
test("Rolling back the final value with rollbackAttribute() causes the record to become clean again", function(assert) {
assert.expect(3);

run(function() {
Expand All @@ -506,12 +506,12 @@ if (isEnabled('ds-reset-attribute')) {
assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty");
person.set('isDrugAddict', false);
assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value");
person.resetAttribute('isDrugAddict');
person.rollbackAttribute('isDrugAddict');
assert.equal(person.get('hasDirtyAttributes'), false, "record becomes clean after resetting property to the old value");
});
});

test("Using resetAttribute on an in-flight record reverts to the latest in-flight value", function(assert) {
test("Using rollbackAttribute on an in-flight record reverts to the latest in-flight value", function(assert) {
assert.expect(4);

var person, finishSaving;
Expand Down Expand Up @@ -546,14 +546,14 @@ if (isEnabled('ds-reset-attribute')) {
person.set('name', "Tomathy");
assert.equal(person.get('name'), "Tomathy");

person.resetAttribute('name');
person.rollbackAttribute('name');
assert.equal(person.get('name'), "Thomas");

finishSaving();
});
});

test("Saving an in-flight record updates the in-flight value resetAttribute will use", function(assert) {
test("Saving an in-flight record updates the in-flight value rollbackAttribute will use", function(assert) {
assert.expect(7);

var person, finishSaving;
Expand Down Expand Up @@ -598,7 +598,7 @@ if (isEnabled('ds-reset-attribute')) {
person.set('name', "Tomny");
assert.equal(person.get('name'), "Tomny");

person.resetAttribute('name');
person.rollbackAttribute('name');
assert.equal(person.get('name'), 'Tomathy');

finishSaving();
Expand Down