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] Add rolling back of a single model attribute #4246

Merged
merged 1 commit into from
Jun 24, 2016

Conversation

courajs
Copy link
Contributor

@courajs courajs commented Mar 18, 2016

First pass at #3705
First feature PR!
Is there any subtlety around in-flight records that I'm missing?

@@ -435,6 +435,7 @@ InternalModel.prototype = {
this.record._notifyProperties(dirtyKeys);

},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't want to introduce additional whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all other methods in this file have whitespace separators, so I left it in as a small style fix.

@pangratz
Copy link
Member

Basically 👍 to the feature! My gut feeling says that this should be handled via the state machine though. Take for example the case where a record in in the invalid state and a property is reset: in this case the corresponding error is removed and the record could become valid. Not sure if there are other cases, but inFlight might also be a noteworthy scenario, as you @courajs already said.

I hope that I have time this weekend to take a deeper look. Will keep you posted!

@pangratz
Copy link
Member

Hey @courajs,

finally I have time to get back to you here. I am very sorry for the delay 😔.

This has been discussed in the team meeting and we agreed that this functionality would be useful. We think that naming the method rollbackAttribute might be confusing though, so we suggest to name it resetAttribute. This method should basically set the attribute to the latest inFlight value or the canonical value from the adapter.

Can you update this PR and:

  • rename the method
  • add test for when an attribute is reset when the record is in flight

Thanks for your work so far! Looking forward to getting this merged!

this.send('propertyWasReset', attributeName);
this.record.notifyPropertyChange(attributeName);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To leave all the logic to the state machine I would suggest adding a new method to the InternalModel which returns the latest truth for an attribute: either the inFlight value or the canonical value. Then, in DS.Model#resetAttribute we simply get the latest value from the internal model and set it. By this everything should basically behave the same as if the attribute would be reset manually to the latest value...

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion!

@courajs
Copy link
Contributor Author

courajs commented Apr 11, 2016

@pangratz Sounds good to me

@pangratz
Copy link
Member

pangratz commented May 8, 2016

@courajs kindly asking if you had any chance of getting this up to date? I would love to see this feature in master 😉 . Ping me if you need further assistance, happy to help!

@courajs
Copy link
Contributor Author

courajs commented May 10, 2016

@pangratz Thanks for the ping! This is mostly updated now, but I bumped into an existing bug with in-flight records we need to fix first. I'll have a PR for that soon and I'll link it here

@courajs
Copy link
Contributor Author

courajs commented May 10, 2016

I believe this build only failed because of #4379, and when it's merged these tests will pass

@courajs
Copy link
Contributor Author

courajs commented May 10, 2016

Confirmed locally, a rebase on top of #4379 and the tests pass.

@pangratz pangratz self-assigned this May 12, 2016
@courajs
Copy link
Contributor Author

courajs commented May 12, 2016

@pangratz I think we're pretty much good here! Any final feedback?

@pangratz
Copy link
Member

pangratz commented May 12, 2016

I meant to review but got caught up in work. I will try to review not later than saturday sunday. Thanks for the work so far!

@courajs
Copy link
Contributor Author

courajs commented May 12, 2016

sounds good :)

@method latestTrueValue
@private
*/
InternalModel.prototype.latestTrueValue = function latestTrueValue(key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this is an internal method, I am not not too happy about the name here to be honest. Coming up with a better one is difficult though 😔 What do you think of lastPreassignedAttributeValue() or even lastCanonicalOrInFlightAttributeValue() or something? I know this is a tiny nitpick, but I was hoping we find a better name here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could settle for lastCanonicalOrInFlightAttributeValue. What about latestSavedValue or latestComittedValue? Since it's not necessarily canonical yet, but it's trying to be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to favor the - admittedly verbose but expressive - lastCanonicalOrInFlightAttributeValue. We can change that always later once we find a better name...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use lastAcknowledgedValue here. This should be clear enough.

@pangratz
Copy link
Member

Overall, this looks very good 🚀

Some few additions and this is ready to :shipit:

  • please add a test which asserts that nothing fancy happens if we reset an attribute, which hasn't changed and a test for reseting an attribute which doesn't exist (just want to make sure a future regression are caught)
  • add another test reseting an in flight attribute for a record which has been saved twice: the value of the attribute should be the one of the latest save()
  • add an entry to FEATURES.md which outlines the basic usage

Thanks!

@courajs
Copy link
Contributor Author

courajs commented May 15, 2016

👍

@courajs courajs force-pushed the rollback-attribute branch 2 times, most recently from 38545cf to c372bb4 Compare May 17, 2016 16:09
@courajs
Copy link
Contributor Author

courajs commented May 17, 2016

@pangratz updated!

@pangratz
Copy link
Member

pangratz commented May 23, 2016

This just needs a rename for the latestTrueValue method (see my comment #4246 (comment)) and a rebase onto latest master, then this PR is good to go 🚀

@courajs
Copy link
Contributor Author

courajs commented May 23, 2016

Whoops! I thought I did that rename 😅
On it

@leifdejong
Copy link

@courajs how is this feature going?

@courajs
Copy link
Contributor Author

courajs commented May 26, 2016

Just needs the rename mentioned above and a rebase when I get a chance

@courajs
Copy link
Contributor Author

courajs commented May 28, 2016

@pangratz updated!

@courajs
Copy link
Contributor Author

courajs commented Jun 23, 2016

@pangratz I think we're finally ready for a merge here. Look good?

@pangratz
Copy link
Member

Awesome! Thanks for the hard work on this @courajs 🚀 🎉

@pangratz pangratz merged commit 3a38988 into emberjs:master Jun 24, 2016
@courajs courajs deleted the rollback-attribute branch June 24, 2016 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants