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

Call validator on first set #1359

Merged
merged 3 commits into from
Dec 16, 2022
Merged

Call validator on first set #1359

merged 3 commits into from
Dec 16, 2022

Conversation

darrenburns
Copy link
Member

@darrenburns darrenburns commented Dec 14, 2022

Fixes #1220

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

@@ -177,8 +177,8 @@ def __set__(self, obj: Reactable, value: ReactiveType) -> None:
validate_function = getattr(obj, f"validate_{name}", None)
# Check if this is the first time setting the value
first_set = getattr(obj, f"__first_set_{self.internal_name}", True)
# Call validate, but not on first set.
if callable(validate_function) and not first_set:
Copy link
Member Author

@darrenburns darrenburns Dec 14, 2022

Choose a reason for hiding this comment

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

@willmcgugan Do you remember the reasoning for this? The comment and the code suggest this behaviour was intentional, but I'm struggling to think of why that might be.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it was a workaround to avoid an issue with the default value invoking validators before the DOM was set up. Maybe prior to init. Could very well be deprecated.

Copy link
Member Author

@darrenburns darrenburns Dec 14, 2022

Choose a reason for hiding this comment

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

Yeah, I think it might be deprecated. I was thinking it would be for the case where you set a reactive value in the constructor (before mounting). That seems to work fine though - the validator is called as expected.

@darrenburns darrenburns marked this pull request as ready for review December 14, 2022 12:12
@darrenburns
Copy link
Member Author

I've left the first_set variable because it's used further down. Not 100% sure it's needed, but I think when I tried to remove it before it broke something, so I'll probably follow up investigating that while looking at some of the other reactive issues.

@willmcgugan willmcgugan merged commit 62d5810 into main Dec 16, 2022
@willmcgugan willmcgugan deleted the validator-first-set branch December 16, 2022 20:11
@rodrigogiraoserrao rodrigogiraoserrao removed their request for review January 10, 2023 15:37
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.

Validators and watchers should run hand-in-hand
2 participants