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

feat: new meta tags API #2958

Merged
merged 5 commits into from
Oct 12, 2020
Merged

feat: new meta tags API #2958

merged 5 commits into from
Oct 12, 2020

Conversation

logaretm
Copy link
Owner

@logaretm logaretm commented Oct 11, 2020

🔎 Overview

The meta tags API wasn't updated or revised since v2 releases. Here are the various problems I see with it:

  • Redundant opposite flags (vaid x invalid, dirty x pristine, touched x untouched)
  • Confusing flags valid vs passed and invalid vs failed
  • Some flags are impossible to be accurate (changed) which will make immutable fields with arrays or objects as values impossible to be accurate.
  • Possibly remove the valid flag, you can always check error messages as an alternative

opposite flags

The new API removes a bunch of flags: untouched, pristine, invalid, passed, failed, validated, and changed. All of these flags information can be inferred from their opposite one and a combination of one or more.

Combined flags

For example, the passed flag is just dirty and valid, changed is a simple comparison of the initial value and current value. And for complex fields, you can use 3rd party libraries for recursive comparisons.

valid flag

Also, there is the topic of the initial valid flag, the problem with this flag is that it is confusing to use. I've found myself using the error message to check if a field is valid or not rather than valid. Because initially, you could have an invalid field but since no validation was done it is impossible to tell.

So we actually have 3 states, false, true, and undefined as in we don't know yet. This is also problematic because undefined and false work pretty much the same as they are both falsy values. So introducing undefined like in v2 will be very confusing.

So checking for error messages works for all purposes of the naive valid flag.

I'm now considering between removing the valid flag completely and changing its behavior to work like passed to make it more accurate, but that would make the two states false and undefined both as false so users of the library must be aware of that caveat.

@logaretm logaretm changed the base branch from master to next October 11, 2020 17:29
@codecov
Copy link

codecov bot commented Oct 11, 2020

Codecov Report

Merging #2958 into next will decrease coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #2958      +/-   ##
==========================================
- Coverage   97.76%   97.62%   -0.15%     
==========================================
  Files          48       48              
  Lines        1030     1011      -19     
  Branches      238      234       -4     
==========================================
- Hits         1007      987      -20     
- Misses         22       23       +1     
  Partials        1        1              
Impacted Files Coverage Δ
packages/core/src/useField.ts 99.12% <100.00%> (-0.12%) ⬇️
packages/core/src/useForm.ts 98.29% <100.00%> (-0.59%) ⬇️
packages/core/src/utils/common.ts 98.24% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f728e51...20abddd. Read the comment docs.

@logaretm logaretm merged commit 7494bfc into next Oct 12, 2020
@logaretm logaretm deleted the feat/new-meta-tags branch October 12, 2020 00:07
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.

1 participant