Optimizing fish_redux 3.0: Architecture, Core Capabilities, and Code Refactoring
Fish_redux 3.0 refactors the framework by collapsing deep inheritance into a BasicComponent base, trimming code from over 3 k to about 1 k lines, streamlining context handling, and preserving core state‑driven UI, middleware, and assembly‑style componentization while adding lightweight extension packages and a roadmap for further Flutter and Dart 2.x enhancements.
fish_redux 2.0 introduced FlowAdapter improvements; the project now moves to a new round of optimization and architectural evolution, aiming for a sustainable 3.x version that preserves the framework’s vitality while enhancing usability, extensibility, and core capabilities.
The article revisits the MVC pattern (Model‑View‑Controller) and its variants (MVP, MVVM), explaining how fish_redux maps State + Reducer to the Model layer, Effect to the Controller, and View to the View layer.
Motivations for fish_redux 3.0 include the rapid growth of client‑side application complexity, lack of a coherent architecture, mismatches between architecture and real requirements, and divergent developer understanding. The goals are to improve ease‑of‑use, maintainability, and to provide a unified programming paradigm for more scenarios.
Core capabilities of fish_redux are summarized as:
State‑driven UI: automatic UI refresh on state changes.
Layered architecture with a Middleware layer for aspect‑oriented extensions.
Assembly‑style componentization that isolates business code and enables reusable components.
Functional decomposition into View, Reducer, and Effect with single‑responsibility functions.
To reduce code size, the framework shrank from over 3 k lines in 2.0 to about 1 k lines in 3.0. Redundant abstractions such as redux_aop , redux_routes , and redux_component_mixin were removed, and several classes were merged.
Component hierarchy was collapsed: the previous deep inheritance chain (Component → Logic → AbstractComponent → AbstractLogic, etc.) was replaced by a simpler structure (Component extends BasicComponent, Adapter extends BasicComponent, BasicComponent as the base).
Context management was also streamlined, consolidating multiple context classes into a single ComponentContext implementation that handles lifecycle, messaging, and caching.
Code comparison (before vs. after) illustrates the simplification:
优化前:
abstract class Component
extends Logic
implements AbstractComponent
{ ... }
abstract class Logic
implements AbstractLogic
{ ... }
abstract class AbstractComponent
implements AbstractLogic
{ ... }
abstract class AbstractLogic
{ ... }
优化后:
class Component
extends BasicComponent
{ ... }
class Adapter
extends BasicComponent
{ ... }
abstract class BasicComponent
{ ... }Extension capabilities (View, Effect, Connector, Adapter) are moved to separate extension packages, allowing the core to stay lightweight while supporting diverse use‑cases such as FlowAdapter variants.
The article concludes with a roadmap: releasing fish_redux 3.0, publishing extension packages, adapting 2.0 to Dart 2.x, improving virtual component lifecycle, and expanding Flutter container support.
Xianyu Technology
Official account of the Xianyu technology team
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.