-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix transitioning into invalid state #3853
Conversation
1b48190
to
be70106
Compare
|
||
equal(get(yehuda, 'isValid'), true, "the record is no longer invalid after changing"); | ||
//shouldn't we use rollbackAttributes. or perhaps a rollbackAttribute method is needed. | ||
//keeping track of changes this is fragile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arenoir I'd like to get a better understanding of what you are suggesting here. Are you saying rollbackAttributes should be responsible for transitioning a model out of the invalid state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the state should be more explicit. The rollback method to me says put this record back to the state it was in when instantiated.
To be semver compatible, this change entails an increase of the major version since it changes the current behavior. Maybe it should be possible to opt out of this behavior via an environment flag and add deprecation warning that the current behavior is about to change in Apart from that, I in general agree with
I think ember data would need a DS.Model.extend({
didUpdateAttribute: function(name, oldValue, newValue) {
var errors = this.get('errors');
errors.clearErrorsFor(attributeName);
if (errors.get('isEmpty')) {
// currently not public ...
this.send('becameValid');
}
}
}); |
@pangratz I would argue that this behavior is a bug and not documented? However I know you are correct; it is a breaking change. I like the idea of a didUpdateAttribute hook and that would restore the behavior thus allowing us to remove the side effect causing event bindings. I will try to implement it. In the mean time I am using this pull request in my application as it fixes a bigger breaking change. |
5c7207b
to
08141f9
Compare
registerHandlers: function(target, becameInvalid, becameValid) { | ||
this.on('becameInvalid', target, becameInvalid); | ||
this.on('becameValid', target, becameValid); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how many apps/addons rely on those events being triggered when registered via model.get('errors').on('becameValid')
or model.get('errors').registerHandlers()
. Since Ember.Evented
is removed in this PR, code which relies on the on
method being available on the DS.Errors
throws an error.
The registerHandler
method isn't advertised but it also hasn't been explicitly marked as @private
so I technically this would break public API, I guess. It also hasn't been explicitly marked as @public
either, so there's that. If I am misinterpreting semver here, please ignore me 😔 .
Again, just to be clear: I am 👍 👍 on removing those events and eventually make clearing the errors for an attribute an opt in solution, but I just want to point out possible implications for semver.
A possible, compatible solution could be to overwrite the on
method and throw a deprecation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behivor is not dicumented but it is definitly used by some applications. Basicly the use case is to be able to implement client side validation in terms of errors
object. Pushing an error in to errors
object transitions the record in to invalid state.
I am fine with deprecating it and removing in next major version. But I am not sure where the deprecation should be. For example in my app, I don't care about events at all. What I do rely on, is the fact that if I am pushing an error in to errors
object, the record became invalid.
💯 agree |
c0ebcf5
to
37452f8
Compare
@bmac okay I have added the Evented functionality back and added my attempt to deprecate it. The problem is we don't want to deprecate |
@arenoir I am not sure how I feel about this... It feels like manual In any case, this probably should go behind a flag to begin with. |
@tchak, I agree with the use case of manually adding errors but I don't think doing so should update the state of the record. If the server has put the record into the invalid state clearing the errors shouldn't change it to 'uncommitted' state. As it stands now calling willCommit from the 'invalid' state first clears the errors inconsequentially changing the state to 'uncommitted' and then transitions the state to 'inflight'. |
@arenoir I am fine with this reasoning.
|
@tchak I agree there should be a public api to change a records state. The I think this will fix some other inconsistent bugs like #3707. |
@arenoir 👍 for warnings. For the rest, I am 👍 on merging it. |
73caa4e
to
1fa0220
Compare
@tchak I switched to warnings and rebased. |
1fa0220
to
a2bb884
Compare
LGTM. @bmac is it ok with you to merge this ? |
remove events from error class add functionality to become valid if errors are removed depricate adding errors change deprecations to regular warnings
a2bb884
to
0057b04
Compare
@bmac okay I rebased with master. Sorry It took so long I was on holiday. |
fix transitioning into invalid state
Thanks @arenoir |
Fixes issue #3851.
Removes events from error class that was causing side effects. I don't think the error class should be responsible for updating the model state.