Skip to content

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

Merged
lesleysin merged 6 commits into
v4from
models-rework
Aug 2, 2025
Merged

breaking: Reworking the widget model API and simplifying registration of custom widgets#35
lesleysin merged 6 commits into
v4from
models-rework

Conversation

@lesleysin

@lesleysin lesleysin commented Jul 24, 2025

Copy link
Copy Markdown
Member
  • 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.

Summary by CodeRabbit

  • Refactor

    • Simplified component registration by requiring only a build factory when registering custom components.
    • Streamlined the element tree structure by replacing fields with abstract getters and adding new getters for child elements.
  • Chores

    • Removed unused type definitions, interfaces, and related code to reduce complexity.
    • Removed export of resource loader module.
  • Bug Fixes

    • Broadened input type handling in data source attributes to accept any list type for tween animations.

…ation logic in DuitRegistry class, removed references to model factories. Updated factory getter methods to match new changes.
@lesleysin lesleysin self-assigned this Jul 24, 2025
@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown

Walkthrough

This change removes the FactoryRecord typedef and updates the registry system to directly store BuildFactory instances, eliminating the use of ModelFactory. The ElementTreeEntry abstract class is refactored to replace fields and nullable properties with non-nullable abstract getters and introduces new abstract getters for child elements. Additionally, a type check in data_source.dart was broadened from List<Map<String, dynamic>> to List. The ResourceLoader interface and its export were removed.

Changes

File(s) Change Summary
Registry API - Factory Record
lib/src/registry_api/factory_record.dart
Deleted file; removed FactoryRecord typedef.
Registry API - Registry
lib/src/registry_api/registry.dart
Refactored to store only BuildFactory in the registry; removed ModelFactory usage; updated method signatures; removed getModelFactory.
UI - Tree Element
lib/src/ui/tree_element.dart
Refactored ElementTreeEntry: removed final fields and nullable properties; replaced with non-nullable abstract getters; added children and child getters.
View Attributes - Data Source
lib/src/view_attributes/data_source.dart
Broadened type check in tweens method from List<Map<String, dynamic>> to List. Added guard to skip non-map elements. No signature changes.
Misc - Index
lib/src/misc/index.dart
Removed export of resource_loader.dart.
Misc - Resource Loader
lib/src/misc/resource_loader.dart
Deleted file; removed abstract interface class ResourceLoader<T>.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DuitRegistry

    Client->>DuitRegistry: register(key, buildFactory)
    DuitRegistry->>DuitRegistry: Store buildFactory in _customComponentRegistry[key]

    Client->>DuitRegistry: getBuildFactory(key)
    DuitRegistry->>DuitRegistry: Retrieve buildFactory from _customComponentRegistry[key]
    DuitRegistry-->>Client: Return buildFactory or null
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

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 a39903d and ae31fcb.

📒 Files selected for processing (2)
  • lib/src/registry_api/registry.dart (2 hunks)
  • lib/src/view_attributes/data_source.dart (1 hunks)
🔇 Additional comments (4)
lib/src/registry_api/registry.dart (3)

9-9: LGTM! Registry simplification is well-executed.

The change from storing FactoryRecord objects to directly storing BuildFactory instances simplifies the registry implementation and aligns with the PR objective of removing unused model factory concepts.


79-84: LGTM! Method signature simplification is clean and consistent.

The updated register method correctly removes the unused ModelFactory parameter and simplifies both the signature and implementation. The documentation update accurately reflects the new behavior.


95-95: LGTM! Direct factory access improves readability.

The simplified access to the build factory from the registry is cleaner and more direct, eliminating the need to navigate through the removed FactoryRecord structure.

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

3748-3752: Type safety concern resolved with defensive programming.

The addition of the guard clause at line 3752 addresses the type safety concern raised in the previous review. The implementation now:

  1. Accepts any List type (more flexible)
  2. Safely skips non-Map elements instead of failing entirely
  3. Prevents runtime exceptions through explicit type checking

This approach is more robust than strict type checking as it gracefully handles mixed-type lists while maintaining safety.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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: 1

🔭 Outside diff range comments (2)
lib/src/registry_api/registry.dart (1)

79-97: Update documentation to reflect the simplified API.

The method documentation still references the removed modelFactory parameter and attributesFactory parameter, but the implementation only accepts buildFactory.

  /// Registers a DUIT element with the specified key, model mapper, renderer, and attributes mapper.
  ///
  /// - The [key] is a unique identifier for the DUIT element.
  ///
- /// - The [modelFactory] is a function that maps the DUIT element to a [ElementTreeEntry].
- ///
  /// - The [buildFactory] is a function that returns the [Widget] representation of the [ElementTreeEntry].
- ///
- /// - The [attributesFactory] is a function that maps the attributes from json to [DuitAttributes.
+ /// - The [buildFactory] is a function that returns the [Widget] representation of the element.
  static void register(
lib/src/ui/tree_element.dart (1)

4-23: Update documentation to reflect the new abstract getter-based design.

The documentation still describes the class as having concrete "properties" like type, id, controlled, and tag, but these have been removed and replaced with abstract getters for only viewController, attributes, children, and child.

/// An abstract base class representing an entry in the DUIT element tree.
///
/// The `ElementTreeEntry` class serves as the foundational class for elements within
/// the DUIT element tree structure. It maintains essential properties such as the type,
/// ID, and control state of the element, as well as optional attributes and a view controller
/// for managing UI state and interactions.
///
/// Type parameter:
/// - [T]: The type of the data associated with the `UIElementController` and `ViewAttribute`.
///
- /// Properties:
- /// - [type]: A string representing the type of the DUIT element.
- /// - [id]: A unique identifier for the DUIT element.
- /// - [controlled]: A boolean indicating whether the DUIT element is controlled.
- /// - [tag]: An optional tag for the DUIT element, which can be used for additional identification.
- /// - [viewController]: An optional UI element controller for handling UI-specific logic.
- /// - [attributes]: Optional view attributes associated with the DUIT element.
+ /// Abstract getters:
+ /// - [viewController]: UI element controller for handling UI-specific logic.
+ /// - [attributes]: View attributes associated with the DUIT element.
+ /// - [children]: List of child elements in the tree structure.
+ /// - [child]: Single child element (nullable).
///
/// Methods:
/// - [renderView]: Abstract method that must be implemented to render the element as a widget.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a7e4d0 and b9bebd5.

📒 Files selected for processing (3)
  • lib/src/registry_api/factory_record.dart (0 hunks)
  • lib/src/registry_api/registry.dart (2 hunks)
  • lib/src/ui/tree_element.dart (1 hunks)
💤 Files with no reviewable changes (1)
  • lib/src/registry_api/factory_record.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (3.32.7)
🔇 Additional comments (5)
lib/src/registry_api/registry.dart (2)

9-9: LGTM: Registry map simplified to store BuildFactory directly.

The change from FactoryRecord to BuildFactory aligns with the PR objective to simplify the widget registration API by removing the model factory abstraction.


117-128: LGTM: getBuildFactory correctly simplified.

The method now directly retrieves the BuildFactory from the map, which is consistent with the new simplified registry design.

lib/src/ui/tree_element.dart (3)

29-31: LGTM: New tree structure getters improve API clarity.

The addition of children and child abstract getters provides a clearer interface for navigating the element tree structure, which aligns with the goal of simplifying the widget model API.


33-33: LGTM: renderView method preserved correctly.

The abstract renderView() method remains unchanged, maintaining the core rendering contract.


25-27: Confirm breaking change for non-nullable viewController & attributes
No concrete implementations of ElementTreeEntry were found in this repo, nor any usages handling null for these getters. However, since this is a public API change it can still break external consumers.

Please:

  • Verify that no external or downstream code expects viewController or attributes to be nullable.
  • If this is intended as a breaking change, bump the major version and/or provide migration guidance.

Comment thread lib/src/registry_api/registry.dart Outdated

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9bebd5 and 717467b.

📒 Files selected for processing (1)
  • lib/src/view_attributes/data_source.dart (1 hunks)

Comment thread lib/src/view_attributes/data_source.dart
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@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: 1

🔭 Outside diff range comments (1)
lib/src/registry_api/registry.dart (1)

79-97: Update documentation to reflect the simplified API.

The method documentation still references the removed modelFactory parameter and mentions attributesFactory which doesn't appear to be part of the current signature.

  /// Registers a DUIT element with the specified key, model mapper, renderer, and attributes mapper.
  ///
  /// - The [key] is a unique identifier for the DUIT element.
  ///
- /// - The [modelFactory] is a function that maps the DUIT element to a [ElementTreeEntry].
- ///
  /// - The [buildFactory] is a function that returns the [Widget] representation of the [ElementTreeEntry].
- ///
- /// - The [attributesFactory] is a function that maps the attributes from json to [DuitAttributes.
+ /// 
+ /// The [buildFactory] creates the widget representation for the custom component.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9b57df and a39903d.

📒 Files selected for processing (1)
  • lib/src/registry_api/registry.dart (2 hunks)
🔇 Additional comments (3)
lib/src/registry_api/registry.dart (3)

9-9: LGTM! Registry simplification aligns with API rework objectives.

The change from storing FactoryRecord to directly storing BuildFactory instances simplifies the registry structure and aligns with the removal of model factories from the API.


88-97: LGTM! Method signature simplification is correct.

The removal of the modelFactory parameter and the simplified storage logic properly implements the API rework objectives.


103-113: LGTM! Direct factory retrieval is more efficient.

The simplified logic to directly retrieve the BuildFactory from the map is cleaner and more efficient than the previous approach through FactoryRecord.

Comment thread lib/src/registry_api/registry.dart
@lesleysin
lesleysin merged commit 998cb07 into v4 Aug 2, 2025
5 checks passed
@lesleysin
lesleysin deleted the models-rework branch August 2, 2025 09:48
@coderabbitai coderabbitai Bot mentioned this pull request Aug 3, 2025
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