Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Aug 18, 2025

Close #5551

Summary by Sourcery

Unify update behavior management behind a new Context interface and introduce a cache decorator as a replacement for the old DataView, updating code, examples, docs, and tests accordingly.

New Features:

  • Introduce a Context API (ft.context) to expose page reference and manage auto-update behavior (enable, disable, reset, query state)

Enhancements:

  • Refactor internal update handling to use the new Context.auto_update_enabled instead of the old UpdateBehavior class
  • Rename the existing DataView decorator to cache with an optional freeze parameter and move it into a dedicated module
  • Update examples and exports to replace direct UpdateBehavior usage with the new Context methods

Documentation:

  • Remove UpdateBehavior documentation and data_view entries, add documentation for Context and the new cache decorator in mkdocs

Tests:

  • Add integration tests for the new Context API and auto-update behavior
  • Update existing tests to use the new cache decorator instead of data_view

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.
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Copy link
Contributor

Copilot AI left a 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_view decorator with cache decorator 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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 18, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

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.
@FeodorFitsner FeodorFitsner merged commit f21dbdd into main Aug 19, 2025
3 of 5 checks passed
@FeodorFitsner FeodorFitsner deleted the v1-move-update-behavior branch August 19, 2025 18:52
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.

v1: Move UpdateBehavior methods to ft.context, rename DataView decorator to cache

3 participants