breaking: Reworking the widget model API and simplifying registration of custom widgets#35
Conversation
…ation logic in DuitRegistry class, removed references to model factories. Updated factory getter methods to match new changes.
WalkthroughThis change removes the Changes
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
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 detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🔇 Additional comments (4)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
modelFactoryparameter andattributesFactoryparameter, but the implementation only acceptsbuildFactory./// 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, andtag, but these have been removed and replaced with abstract getters for onlyviewController,attributes,children, andchild./// 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
📒 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
FactoryRecordtoBuildFactoryaligns 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
BuildFactoryfrom 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
childrenandchildabstract 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-nullableviewController&attributes
No concrete implementations ofElementTreeEntrywere found in this repo, nor any usages handlingnullfor 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
viewControllerorattributesto be nullable.- If this is intended as a breaking change, bump the major version and/or provide migration guidance.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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
modelFactoryparameter and mentionsattributesFactorywhich 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
📒 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
FactoryRecordto directly storingBuildFactoryinstances 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
modelFactoryparameter 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
BuildFactoryfrom the map is cleaner and more efficient than the previous approach throughFactoryRecord.
* 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
Summary by CodeRabbit
Refactor
Chores
Bug Fixes