-
Notifications
You must be signed in to change notification settings - Fork 815
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
Data binding and more #4075
Data binding and more #4075
Conversation
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.
LGTM
Co-authored-by: Darren Burns <[email protected]>
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 left a couple of questions for possible improvements.
def set( | ||
self, | ||
display: bool | None = None, | ||
visible: bool | None = None, | ||
disabled: bool | None = None, | ||
loading: bool | None = None, | ||
) -> DOMQuery[QueryType]: |
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 thought this would take **kwargs
and just set whatever keyword argument(s) is/are provided on all of the DOMNodes. Wouldn't that be more helpful than being prescriptive about the specific attributes we can 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.
It's for the benefit of typechecking mainly.
disabled: bool | None = None, | ||
loading: bool | None = None, |
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.
disabled
and loading
are attributes on widgets, not on DOM nodes. Won't that be a problem? Maybe due to typing issues or inconsistencies?
yield WorldClock("Europe/Paris").data_bind(WorldClockApp.time) | ||
yield WorldClock("Asia/Tokyo").data_bind(WorldClockApp.time) | ||
``` | ||
|
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.
|
||
Args: | ||
compose_parent: The node doing the binding. |
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.
Args: | |
compose_parent: The node doing the binding. |
def make_setter(variable_name: str) -> Callable[[object], None]: | ||
"""Make a setter for the given variable name. | ||
|
||
Args: | ||
variable_name: Name of variable being set. | ||
|
||
Returns: | ||
A callable which takes the value to set. | ||
""" | ||
|
||
def setter(value: object) -> None: | ||
"""Set bound data.""" | ||
_rich_traceback_omit = True | ||
Reactive._initialize_object(self) | ||
setattr(self, variable_name, value) | ||
|
||
return setter |
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.
Can't this be defined outside of the for
loop?
self.watch( | ||
compose_parent, | ||
reactive.name, | ||
setter, |
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.
Why not partial(setattr, self, variable_name)
?
Bit of a mixed bag. Added a number of things while working on Tailless. The most notable is probably the data binding.
See changelog for details.