-
Notifications
You must be signed in to change notification settings - Fork 767
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
Conversation
@@ -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: |
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.
@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.
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 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.
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.
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.
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. |
Fixes #1220