-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add dirty check #157
Add dirty check #157
Conversation
src/field-accessor.ts
Outdated
return false; | ||
} | ||
if (Array.isArray(this.value)) { | ||
return toJS(this.value).length !== this._originalValue.length; |
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.
Is this a proper dirty check? Because it looks like it only checks if the array is equal in length. So if I change one value in the array but keep it the same length, will it correctly flag as dirty?
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.
Good catch! I came across this issue while implementing the restore functionality.
This has been fixed in that PR by comparing the values in its stringified form when the lengths are the same.
Revert state
This PR adds functionality for dirty checks on accessors.
For each accessor the initial value (this also includes any value through
addModeDefaults
) is saved and compared to see if this has been changed ever since.After a succesful save of the
FormAccessor
the initial value is updated and thus the dirty state is reset.Each
accessor
has aisDirty
property to check for this state, also aresetDirtyState
is present on eachaccessor
to reset this manually.