-
-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce bindable dataclass fields (#3987)
This PR follows up an idea #3957 to introduce bindable `dataclasses.dataclass` fields. The main challenge is to marry `bindableProperty` with `dataclasses.field`, and by that preserve native dataclass features. The proposed idea is to use a wrapper around dataclasses.field that updates passed `metadata`, adding nicegui-specific options (for now just a "bindable" flag). Then use it to add `bindableProperties` retroactively on dataclass type postprocessing (much like it is done in [ dataclasses_json.config](https://github.com/lidatong/dataclasses-json?tab=readme-ov-file#encode-or-decode-from-camelcase-or-kebab-case)) # Usage example ```py @bindable_dataclass @DataClass class MyClass: x: float = dataclass_bindable_field(default=1.0) ``` # Known tradeoffs - Access to default field value through class attribute (e.g. `MyClass.x`) is lost. --------- Co-authored-by: Falko Schindler <[email protected]>
- Loading branch information
1 parent
5032ca4
commit 1fb2d12
Showing
5 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters