Feature<State, Msg, Effect> class abstract interface

Core interface for building features.

Inspired by The Elm Architecture.

This interface encapsulates the primary elements of a feature:

  • State: Represents the feature's current state.
  • Msg: Defines messages or events that may alter the state.
  • Effect: Represents side effects triggered by messages but do not modify state directly.

Due to its generic nature, this interface may appear complex. To simplify usage, consider defining type aliases and factory functions for specific features:

typedef JsonFeature = Feature<JsonState, JsonMsg, JsonEffect>;

JsonFeature jsonFeatureFactory() => JsonFeature(
      initialState: const JsonState.init(),
      update: _jsonUpdate,
      effectHandlers: [_jsonEffectHandler],
      initialEffects: const [],
    );
Implemented types
Implementers
Available extensions
Annotations
  • @experimental

Constructors

Feature({required State initialState, required Update<State, Msg, Effect> update, List<EffectHandler<Effect, Msg>> effectHandlers = const [], List<Effect> initialEffects = const [], List<Effect> disposableEffects = const []})
Creates a new Feature instance.
factory

Properties

disposableEffects List<Effect>
Effects executed when the feature is disposed.
no setter
effects Stream<Effect>
A stream of side effects triggered by the feature.
no setter
hashCode int
The hash code for this object.
no setterinherited
initialEffects List<Effect>
Initial effects executed when the feature is created.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → State
The current state of the feature.
no setter
stateStream Stream<State>
A stream providing updates to the feature's state.
no setter

Methods

accept(Msg message) → void
Processes an incoming message.
dispose() Future<void>
Cleans up resources when the feature is no longer needed.
override
init() FutureOr<void>
Initializes the feature and prepares it for usage.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
observe(FeatureObserver<S, M, E> observer) Feature<S, M, E>

Available on Feature<S, M, E>, provided by the FeatureObserverWrapperHelper extension

Wraps the feature with the specified observer.
toString() String
A string representation of this object.
inherited
wrapEffects<E extends Effect>(EffectHandler<E, Msg> handler) Feature<State, Msg, Effect>

Available on Feature<State, Msg, Effect>, provided by the EffectHandlerWrapperUtils extension

Wraps the feature with an EffectHandler for effects of type E.

Operators

operator ==(Object other) bool
The equality operator.
inherited