Store<St> class

Creates a Redux store that holds the app state.

The only way to change the state in the store is to dispatch a ReduxAction. You may implement these methods:

  1. AppState reduce() ➜ To run synchronously, just return the state: AppState reduce() { ... return state; } To run asynchronously, return a future of the state: Future

  2. FutureOr<void> before() ➜ Runs before the reduce method. If it throws an error, then reduce will NOT run. To run before synchronously, just return void: void before() { ... } To run asynchronously, return a future of void: Future

  3. void after() ➜ Runs after reduce, even if an error was thrown by before or reduce (akin to a "finally" block). If the after method itself throws an error, this error will be "swallowed" and ignored. Avoid after methods which can throw errors.

  4. bool abortDispatch() ➜ If this returns true, the action will not be dispatched: before, reduce and after will not be called, and the action will not be visible to the StoreTester. This is only useful under rare circumstances, and you should only use it if you know what you are doing.

  5. Object wrapError(error) ➜ If any error is thrown by before or reduce, you have the chance to further process it by using wrapError. Usually this is used to wrap the error inside of another that better describes the failed action. For example, if some action converts a String into a number, then instead of throwing a FormatException you could do: wrapError(error) => UserException("Please enter a valid number.", cause: error)


• ActionObserver observes the dispatching of actions, and may be used to print or log the dispatching of actions.

• StateObservers receive the action, stateIni (state right before the action), stateEnd (state right after the action), and are used to log and save state.

• ErrorObservers may be used to observe or process errors thrown by actions.

For more info, see: https://pub.dartlang.org/packages/async_redux

Implementers

Constructors

Store({required St initialState, Object? environment, bool syncStream = false, TestInfoPrinter? testInfoPrinter, List<ActionObserver<St>>? actionObservers, List<StateObserver<St>>? stateObservers, Persistor<St>? persistor, ModelObserver? modelObserver, ErrorObserver<St>? errorObserver, WrapReduce<St>? wrapReduce, WrapError<St>? wrapError, bool? defaultDistinct, CompareBy? immutableCollectionEquality, int? maxErrorsQueued})

Properties

defaultDistinct bool
no setter
dispatchCount int
no setter
env Object?
no setter
errors Queue<UserException>
no setter
hashCode int
The hash code for this object.
no setterinherited
immutableCollectionEquality CompareBy?
  • If null (the default), view-models which are immutable collections will be compared by their default equality.

  • If CompareBy.byDeepEquals, view-models which are immutable collections will be compared by their items, one by one (potentially slow comparison).

  • If CompareBy.byIdentity, view-models which are immutable collections will be compared by their internals being identical (very fast comparison).

  • no setter
    isShutdown bool
    no setter
    modelObserver ModelObserver?
    no setter
    onChange Stream<St>
    A stream that emits the current state when it changes.
    no setter
    onReduce Stream<TestInfo<St>>
    Used by the storeTester.
    no setter
    reduceCount int
    no setter
    runtimeType Type
    A representation of the runtime type of the object.
    no setterinherited
    state → St
    The current state of the app.
    no setter
    stateTimestamp DateTime
    The timestamp of the current state in the store, in UTC.
    no setter
    testInfoPrinter TestInfoPrinter?
    no setter

    Methods

    createTestInfoSnapshot(St state, ReduxAction<St> action, Object? error, Object? processedError, {required bool ini}) → void
    defineState(St state) → void
    Beware: Changes the state directly. Use only for TESTS.
    deletePersistedState() Future<void>
    Asks the Persistor to delete the saved state from the persistence.
    dispatch(ReduxAction<St> action, {bool notify = true}) FutureOr<ActionStatus>
    Runs the action, applying its reducer, and possibly changing the store state. Note: dispatch is of type Dispatch.
    dispatchAsync(ReduxAction<St> action, {bool notify = true}) Future<ActionStatus>
    Runs the action, applying its reducer, and possibly changing the store state. Note: dispatchAsync is of type DispatchAsync.
    dispatchSync(ReduxAction<St> action, {bool notify = true}) ActionStatus
    Runs the action, applying its reducer, and possibly changing the store state. Note: dispatchSync is of type DispatchSync.
    getAndRemoveFirstError() UserException?
    Gets the first error from the error queue, and removes it from the queue.
    initTestInfoController() → void
    Turns on testing capabilities, if not already.
    initTestInfoPrinter(TestInfoPrinter testInfoPrinter) → void
    Changes the testInfoPrinter.
    noSuchMethod(Invocation invocation) → dynamic
    Invoked when a nonexistent method or property is accessed.
    inherited
    pausePersistor() → void
    Pause the Persistor temporarily.
    persistAndPausePersistor() → void
    Persists the current state (if it's not yet persisted), then pauses the Persistor temporarily.
    resumePersistor() → void
    Resumes persistence by the Persistor, after calling pausePersistor or persistAndPausePersistor.
    shutdown() → void
    Call this method to shut down the store. It won't accept dispatches or change the state anymore.
    teardown({St? emptyState}) Future
    Closes down the store so it will no longer be operational. Only use this if you want to destroy the Store while your app is running. Do not use this method as a way to stop listening to onChange state changes. For that purpose, view the onChange documentation.
    toString() String
    A string representation of this object.
    inherited
    waitCondition(bool condition(St), {int? timeoutInSeconds}) Future<void>
    Returns a future which will complete when the given condition is true. The condition can access the state. You may also provide a timeoutInSeconds, which by default is null (never times out).

    Operators

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