-
Notifications
You must be signed in to change notification settings - Fork 600
v1: Move UpdateBehavior methods to ft.context, rename DataView decorator to cache #5570
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
Conversation
Replaces usage of UpdateBehavior with a new context API for managing auto update state across the codebase. Updates examples, main app logic, and event handling to use ft.context methods. Removes UpdateBehavior from public API and documentation, adds integration tests for auto update behavior, and updates documentation and navigation to reflect the new context API.
Added detailed docstrings to Context class methods for better clarity and documentation. Improved type hints and assertions, including stricter return type for page property and assertion to ensure context is associated with a page.
Renamed and enhanced the data_view decorator to cache, adding a freeze option for control freezing. Updated imports, __all__, and all usages in tests to use the new cache decorator.
Introduces ParamSpec and TypeVar for improved type safety in the cache decorator. Adds overloads to the cache function and updates argument and return type annotations for better compatibility with type checkers.
Added assertions for ft.context.page in autoupdate.py to ensure context is associated with a page. Renamed test_autoupdate.py to test_context.py and added a test to verify that accessing ft.context.page outside of a Flet app raises an exception.
Updated documentation for the Context class with usage examples and improved docstrings. Exposed Context in the public API via __init__.py and reorganized mkdocs navigation to move Context under Utility. Minor code reordering for clarity.
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.
We've reviewed this pull request using the Sourcery rules engine
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.
Pull Request Overview
This PR refactors Flet's update behavior management by introducing a unified Context API and replacing the DataView decorator with a more flexible cache decorator. The main goals are to centralize auto-update control through ft.context and provide better caching functionality with optional freezing.
- Move UpdateBehavior methods to new Context class accessible via
ft.context - Replace
data_viewdecorator withcachedecorator that supports optional freezing - Update all code, examples, and documentation to use the new APIs
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/flet/controls/context.py |
Introduces Context class with auto-update management methods and exposes context instance |
src/flet/controls/cache.py |
New cache decorator implementation with optional freeze parameter |
src/flet/controls/data_view.py |
Removes old data_view decorator implementation |
src/flet/__init__.py |
Updates exports to include cache and Context, removes data_view and UpdateBehavior |
tests/test_object_diff_frozen.py |
Updates tests to use new cache decorator syntax |
integration_tests/test_context.py |
Adds integration tests for new Context API |
| Various other files | Updates imports and usage to use new context API instead of UpdateBehavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Deploying flet-docs with
|
| Latest commit: |
2d44d56
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6fdd7370.flet-docs.pages.dev |
| Branch Preview URL: | https://v1-move-update-behavior.flet-docs.pages.dev |
Co-authored-by: Copilot <[email protected]>
Added example scripts for disabling auto update and accessing page via context. Updated documentation to include new examples and improved references to ft.context. Renamed window_width and window_height to web_popup_window_width and web_popup_window_height in Page class for clarity.
Added documentation for 'cache' and 'control' decorators. Updated mkdocs navigation to include new decorator docs. Refactored the 'control' decorator in base_control.py to rename 'cls_or_type_name' to 'dart_widget_name' and improved docstring for clarity. Renamed test functions in test_object_diff_frozen.py for consistency.
Introduces a basic example for the cache decorator in Flet, updates documentation to include usage and example, and refines the cache decorator implementation with improved comments and docstring. Also fixes a minor docstring typo in base_control.py.
Improved the docstring for the control decorator by clarifying references to @DataClass and its keyword arguments, and enhancing formatting for better readability.
Close #5551
Summary by Sourcery
Unify update behavior management behind a new Context interface and introduce a
cachedecorator as a replacement for the old DataView, updating code, examples, docs, and tests accordingly.New Features:
ft.context) to expose page reference and manage auto-update behavior (enable, disable, reset, query state)Enhancements:
cachewith an optionalfreezeparameter and move it into a dedicated moduleDocumentation:
Tests: