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

fix: $rewardEarly implementation #1240

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

renatodeleao
Copy link

Summary

  1. Moved $lastInvalid sync assignment from the results.$invalid computed
    because computed props should be side-effect free.
  2. Added $lastCommittedOn as a watch source because 3.4.x vue will cache
    computed more aggressively and $lastInvalidState would be out of sync
    in the "commit() called when model valid" scenario:
    1. $commit() sets $lastInvalidState to true
    2. validators run and return invalid as false
    3. result.$invalid computed is already false (initial), so it will not recompute (cached)
    4. the watcher will not be triggered because $result.$invalid dep did not change.
    5. last $invalidState is not sync to false — to match result.$invalid, and thus $model change triggers validators to run immediately.
  3. flush "post" is required for async validators to work in this mode, otherwise
    last invalid state will be flipped to false since sync validators run first
    and turn invalid to false "before" pending is set to true and it will prevent
    them from running (Guessing). At least is required for 3.4.x and that's
    the version the majority should be using.

I don't know if it's out-of-scope of this PR to update vue, but 3.4.x
brought many changes to computed optimization which vuelidate relies on
heavily and it's the future.

fixes #1237

Metadata

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

closes vuelidate#1237

1. Moved $lastInvalid assignment from the results.$invalid computed
   because computed props should be side-effect free.
2. Added $lastCommittedOn as a watch source because 3.4.x vue will cache
   computed more aggressively and $lastInvalidState would be out of sync
   in the "commit() when valid" scenario:
   - commit() sets $lastInvalidState to true
   - validators run and return invalid as false
   - result.$invalid is already false, so it will not recompute (cached)
   - the watcher will not be triggered because $result.$invalid dep did
     not change.
   - last $invalidState is not set to false, and thus $model change
     triggers validators to run.
   I don't know if it's out-of-scope of this PR to update vue, but 3.4.x
   brought many changes to computed optimization which vuelidate relies on
   heavily and it's the future.
3. flush "post" is required for async validators to work in this mode, otherwise
   last invalid state will be flipped to false since sync validators run first
   and turn invalid to false "before" pending is set to true and it will prevent
   them from running (Guessing). At least is required for 3.4.x and that's
   the version the majority should be using.
@renatodeleao renatodeleao changed the title fix: rewardEarly implementation fix: $rewardEarly implementation Apr 14, 2024
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.

$rewardEarly stops working if a previous field is invalid
1 participant