Skip to content

feat: action debounce and throttle configuration#38

Merged
lesleysin merged 3 commits into
v4from
debounce-and-throttle
Aug 6, 2025
Merged

feat: action debounce and throttle configuration#38
lesleysin merged 3 commits into
v4from
debounce-and-throttle

Conversation

@lesleysin

@lesleysin lesleysin commented Aug 5, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Introduced support for execution options on server actions, allowing actions to be configured with throttling or debouncing behavior.
    • Added new configuration options to control how frequently actions are executed, including customizable timing.
    • Enhanced data source handling to parse and apply execution modifiers and options from configuration.
  • Documentation

    • Included detailed usage examples and explanations for the new execution options and modifiers.

…h throttle and debounce modifiers, updated ServerAction classes and their descendants to support the new options. Updated parsing methods and added corresponding lookup tables for execution modifiers.
@lesleysin lesleysin self-assigned this Aug 5, 2025
@coderabbitai

coderabbitai Bot commented Aug 5, 2025

Copy link
Copy Markdown

Walkthrough

This change introduces execution throttling and debouncing support for server actions. A new ExecutionOptions class and ExecutionModifier enum are added, with parsing and lookup support integrated into the data source layer. All server action types are extended to accept and propagate optional execution options, and exports are updated to expose the new API.

Changes

Cohort / File(s) Change Summary
ServerAction execution options propagation
lib/src/action_api/action.dart
Adds executionOptions field to ServerAction and propagates it through all subclasses and their fromJson constructors.
Execution options API
lib/src/action_api/execution_options.dart
Introduces ExecutionModifier enum and ExecutionOptions class with documentation for throttling and debouncing.
API export update
lib/src/action_api/index.dart
Exports execution_options.dart to make new execution options API public.
Data source parsing for execution options
lib/src/view_attributes/data_source.dart
Adds methods to parse and cache ExecutionModifier and ExecutionOptions from JSON maps in the data source extension; refactors null checks and enum lookups for consistency.
Enum lookup tables
lib/src/view_attributes/lookup.dart
Adds string and integer lookup tables for ExecutionModifier to support parsing from JSON.
Test coverage for execution options parsing
test/data_source_test.dart
Adds tests for executionOptions() method covering parsing, defaults, error cases, caching, and key customization; updates color parsing test expectations.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DuitDataSource
    participant ServerAction
    participant ExecutionOptions

    Client->>DuitDataSource: Provide JSON input
    DuitDataSource->>DuitDataSource: executionOptions()
    DuitDataSource->>ExecutionOptions: Parse modifier & duration
    DuitDataSource-->>ServerAction: Return ExecutionOptions
    ServerAction->>ServerAction: Construct with executionOptions
    ServerAction-->>Client: Action instance with options
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Improve lookup tables for enums #36: Both PRs modify enum lookup tables in lookup.dart, with this PR adding new tables for ExecutionModifier and the related PR extending lookup tables for other enums. Both focus on enhancing enum lookup mechanisms.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aca19e2 and 962f6fe.

📒 Files selected for processing (2)
  • lib/src/view_attributes/data_source.dart (67 hunks)
  • test/data_source_test.dart (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the duit_kernel framework, lookup table access in duitdatasource methods intentionally uses non-n...
Learnt from: lesleysin
PR: Duit-Foundation/duit_kernel#38
File: lib/src/view_attributes/data_source.dart:3977-4010
Timestamp: 2025-08-05T07:27:20.340Z
Learning: In the duit_kernel framework, lookup table access in DuitDataSource methods intentionally uses non-null assertions (!) instead of null coalescing (??) to implement a fail-fast approach. This is an architectural decision where the DSL layer (duit_go or duit_js) is responsible for data contract compliance, and runtime exceptions serve as indicators of contract violations rather than being silently handled with fallbacks.

Applied to files:

  • lib/src/view_attributes/data_source.dart
🔇 Additional comments (5)
test/data_source_test.dart (1)

6085-6228: LGTM! Well-structured and comprehensive test coverage for the new executionOptions method.

The new test group follows the established patterns in the file and provides thorough coverage of the executionOptions() method functionality. The tests appropriately verify:

  • Parsing from maps with both string and integer modifier types
  • Default value handling for null and invalid inputs
  • Instance preservation when already parsed
  • Custom key parameter usage
  • Error handling for invalid modifier values

The test structure is consistent with other test groups and properly validates that parsed values are stored back into the data source.

lib/src/view_attributes/data_source.dart (4)

217-217: LGTM! Consistent null handling improvements.

The null checks have been consistently simplified across all parsing methods from compound conditions to simple if (value == null) return defaultValue; statements. This improves readability while maintaining the same behavior.

Also applies to: 247-247, 251-251, 501-501, 569-569, 602-602, 669-669, 723-723, 756-756, 796-796, 828-828, 861-861, 1005-1005, 1038-1038, 1102-1102, 1134-1134, 1168-1168, 1202-1202, 1221-1221, 1286-1286, 1342-1342, 1389-1389, 1451-1451, 1483-1483, 1516-1516, 1550-1550, 1571-1571, 1634-1634, 1665-1665, 1698-1698, 1732-1732, 1771-1771, 1810-1810, 1844-1844, 1878-1878, 1912-1912, 1946-1946, 1980-1980, 2014-2014, 2096-2096, 2129-2129, 2161-2161, 2323-2323, 2349-2349, 2383-2383, 2523-2523, 2557-2557, 2639-2639, 2671-2671, 2690-2690, 2746-2746, 2779-2779, 2813-2813, 2847-2847, 2881-2881, 3033-3033, 3107-3107, 3139-3139, 3186-3186, 3324-3324, 3382-3382, 3471-3471, 3510-3510, 3543-3543, 3576-3576, 3767-3767, 3803-3803


3832-3863: Private method follows established patterns correctly.

The _executionModifier method follows the same pattern as other enum parsing methods in the class, using lookup tables for both string and integer values with intentional non-null assertions. The method signature and implementation are consistent with the codebase patterns.


3865-3885: Helper method correctly constructs ExecutionOptions.

The _executionOptionsFromMap method properly creates an ExecutionOptions instance by extracting the modifier and duration from the JSON map using the established parsing methods. The implementation follows the same pattern as other _fromMap helper methods in the codebase.


3887-3917: Public parsing method integrates well with framework patterns.

The executionOptions method follows the exact same pattern as other complex type parsing methods in the class:

  1. Checks if value is already the target type
  2. Returns defaultValue for null values
  3. Uses switch statement to handle Map<String, dynamic> case
  4. Stores parsed result back into JSON map for caching
  5. Returns defaultValue for unhandled cases

The method signature, documentation, and implementation are consistent with established conventions.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c44e929 and d612e0e.

📒 Files selected for processing (5)
  • lib/src/action_api/action.dart (6 hunks)
  • lib/src/action_api/execution_options.dart (1 hunks)
  • lib/src/action_api/index.dart (1 hunks)
  • lib/src/view_attributes/data_source.dart (1 hunks)
  • lib/src/view_attributes/lookup.dart (1 hunks)
🔇 Additional comments (10)
lib/src/view_attributes/lookup.dart (1)

1417-1434: LGTM! Well-integrated lookup tables.

The new ExecutionModifier lookup tables are well-implemented and follow the established patterns in this file perfectly. The comprehensive string mapping (including both simple and fully-qualified names) and clear integer mapping provide flexible deserialization options.

lib/src/action_api/index.dart (1)

9-9: LGTM! Proper API exposure.

The export statement correctly exposes the new execution options functionality through the public API, following the established pattern in this index file.

lib/src/action_api/execution_options.dart (2)

1-40: Excellent enum design and documentation.

The ExecutionModifier enum is well-designed with clear behavioral distinctions:

  • Throttle: Executes first call, ignores subsequent calls within duration
  • Debounce: Delays execution until quiet period expires

The comprehensive documentation with practical examples makes the API easy to understand and use correctly.


80-100: Well-designed data class with comprehensive documentation.

The ExecutionOptions class is properly designed as a final data class with:

  • Required parameters ensuring complete configuration
  • Clear field documentation explaining their purposes
  • Excellent class-level documentation with practical examples

The design enforces that both modifier and duration are always specified, preventing incomplete configurations.

lib/src/action_api/action.dart (4)

29-36: Clean integration into base class.

The executionOptions field is properly integrated into the ServerAction base class following established patterns. Making it nullable is appropriate since execution options are optional functionality.


62-76: Consistent integration pattern.

The LocalAction class properly integrates execution options using:

  • Super parameter for clean constructor delegation
  • Consistent JSON parsing pattern using DuitDataSource

The implementation follows established conventions in the codebase.


103-121: Proper integration following established patterns.

The TransportAction changes maintain consistency with other action types, using the same super parameter pattern and JSON parsing approach via DuitDataSource.


133-150: Approve ScriptAction integration

The ScriptAction.fromJson implementation correctly delegates to source.executionOptions(), and the executionOptions method is defined in lib/src/view_attributes/data_source.dart, returning an ExecutionOptions (or null) based on the JSON input. This matches the pattern used by other action types and requires no further changes.

lib/src/view_attributes/data_source.dart (2)

4026-4032: LGTM on the conversion method.

The _executionOptionsFromMap method correctly uses the existing duration() method and the _executionModifier() helper to construct an ExecutionOptions instance. The implementation is clean and follows the established patterns in the codebase.


4048-4064: LGTM on the main execution options method.

The executionOptions method follows the established pattern used throughout the DuitDataSource class for parsing complex objects from JSON. It properly handles type checking, caching, and graceful fallback to default values.

Comment thread lib/src/view_attributes/data_source.dart
Comment thread lib/src/view_attributes/data_source.dart
- Refactor DuitDataSource methods with one-line return and fail-fast approach at lookup tables work
@lesleysin
lesleysin merged commit 9bbdf79 into v4 Aug 6, 2025
5 checks passed
@lesleysin
lesleysin deleted the debounce-and-throttle branch August 6, 2025 15:19
lesleysin added a commit that referenced this pull request Nov 5, 2025
* breaking: DuitDataSource (#32)

* experiment - removing attribute support

* wip

* wip

* wip

* refacror ViewAttributes class

* Added  tests

* wip

* Added early exit from methods

* Added new functions for handling JSON parsing results, improved default result return logic, and added table mapping for BlendMode and FloatingActionButtonLocation.

* docs

* add tests

* Added tests

* Removed static mapping tables for Clip, TextAlign, TextOverflow and TextWidthBasis in the DuitDataSource class.

* Added new methods for JSON processing, including support for textDecorationStyle, fontWeight, fontStyle and other attributes. Improved logic for returning default values ​​and added corresponding tests.

* Added tests

* Removed unused methods and added new functions to handle theme rules and image filters. Updated tests to check new features and JSON processing logic.

* Upd .gitignore

* wip

* Upd tests, added Tween parser

* Removed ventilation methods, added new functions for widget handling. Updated tests to check new features and JSON handling logic.

* Refactored functions for creating InputBorder and ShapeBorder from a map, as well as corresponding lookup tables. Simplified logic for selecting the border type.

* Added docs

* upd actions config

* wip

* wip

* Update test/theme_test.dart

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* clean dead code

* fix

* Update lib/src/view_attributes/lookup.dart

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Added export of Command.dart file to action_api and removed it from animation_api. Updated data references in DuitDataSource class to use new "stretchModes" key. Fixes to tests to match changes in step data.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Remote commands API update (#33)

* breaking: Themes refactoring (#34)

* Registry API update: Added new RefWithTarget class, changed component initialization and registration functions, removed unused files, and improved export structure. Updated tests and removed deprecated topic tokens.

* upd workflow

* breaking: Reworking the widget model API and simplifying registration of custom widgets (#35)

* Removed unused factory_record.dart file and updated component registration logic in DuitRegistry class, removed references to model factories. Updated factory getter methods to match new changes.

* Small fix for tweens parser

* rm unused API part

* Update lib/src/registry_api/registry.dart

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* review fixes

* fix

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Improve lootup tables for enums (#36)

* Flutter types json encoding (#37)

* Added encoding functions for: Duration, Size, EdgeInsets, TextStyle, Color, LinearGradient, BoxShadow, Offset, BoxDecoration, BorderRadius, Border, BorderSide, InputBorder, InputDecoration, VisualDensity, ScrollPhysics, ShapeBorder

* wip

* Added tests

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix tests

* Added docs

* dart format

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* feat: action debounce and throttle configuration (#38)

* Added execution options for actions: added ExecutionOptions class with throttle and debounce modifiers, updated ServerAction classes and their descendants to support the new options. Updated parsing methods and added corresponding lookup tables for execution modifiers.

* - Added test
- Refactor DuitDataSource methods with one-line return and fail-fast approach at lookup tables work

* fix Color parsers behavior

* refactoring: improved color handling in _colorFromList function

Changed the typification function of the _colorFromList parameter from List<num> to List, added preprocessing of color data to ensure correct conversion. Updated the corresponding calls in the JSON parsing and processing methods in the DuitDataSource class.

* feat: Fragments registration in DuitRegistry (#39)

Added a new static method registerFragment for registering fragments by key and a method getFragment for receiving a fragment by key with logging in case of absence. Also added an internal registry of fragments _fragmentRegistry.

* Component system refactor (#40)

* Components refactoring via JSON patching instead of Map mutation

* Added tests for json patching and components patches generation

* Review fixes

* Upd lookup table for Curves

* Remover legacy API references

* feat: DuitDataSource methods extension (#41)

* Extend parser for BorderRadius type, added Radius type parsing, upd tests

* fix tests

* Added new Size parsing behavior

* wip

* feat: Custom json reviver (#42)

* Refactor env variables, refactor analysis issues in test files, added FlutterPropertyKeys class

* wip

* wip

* wip

* Fixed analysis issues

* wip

* Fixed getActionDependencies and childObjects methods

* Upd env variables keys

* Code review fixes

* Fix test

* Upd post-merge workflow
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.

1 participant