WaitAction<St> class
WaitAction and Wait work together to help you create boolean flags that
indicate some process is currently running. For this to work your store state
must have a Wait
field named wait
, and then:
- The state must have a
copy
orcopyWith
method that copies this field as a named parameter. For example:
class AppState {
final Wait wait;
AppState({this.wait});
AppState copy({Wait wait}) => AppState(wait: wait);
}
OR:
- You must use the BuiltValue package https://pub.dev/packages/built_value,
which automatically creates a
rebuild
method.
OR:
- You must use the Freezed package https://pub.dev/packages/freezed,
which automatically creates the
copyWith
method.
OR:
- Inject your own WaitReducer implementation into WaitAction by replacing the static variable WaitAction.reducer with a callback that changes the wait object as you see fit.
OR:
- Don't use the WaitAction, but instead create your own
MyWaitAction
that uses the Wait object in whatever way you want.
- Inheritance
-
- Object
- ReduxAction<
St> - WaitAction
Constructors
- WaitAction.add(Object? flag, {Object? ref, Duration? delay})
- Adds a flag that indicates some process is currently running. Optionally, you can also have a flag-reference called ref.
- WaitAction.clear([Object? flag])
- Clears (removes) the flag, with all its references. Removing the flag indicating some process finished running.
- WaitAction.remove(Object? flag, {Object? ref, Duration? delay})
- Removes a flag previously added with the add method. Removing the flag indicating some process finished running.
Properties
- delay → Duration?
-
final
-
dispatch
→ Dispatch<
St> -
no setterinherited
-
dispatchAsync
→ DispatchAsync<
St> -
no setterinherited
-
dispatchSync
→ DispatchSync<
St> -
no setterinherited
- env → Object?
-
no setterinherited
- flag → Object?
-
final
- hasFinished → bool
-
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isFinished → bool
-
Returns true only if the action finished with no errors.
In other words, if the methods before, reduce and after all finished executing
without throwing any errors.
no setterinherited
- microtask → Future
-
To wait for the next microtask:
await microtask;
no setterinherited - operation → WaitOperation
-
final
- ref → Object?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → St
-
no setterinherited
- stateTimestamp → DateTime
-
no setterinherited
- status → ActionStatus
-
no setterinherited
-
store
→ Store<
St> -
no setterinherited
Methods
-
abortDispatch(
) → bool -
If this returns true, the action will not be dispatched:
before
,reduce
andafter
will not be called, and the action will not be visible to theStoreTester
. This is only useful under rare circumstances, and you should only use it if you know what you are doing.inherited -
after(
) → void -
This is an optional method that may be overridden to run during action
dispatching, after
reduce
. If this method throws an error, the error will be swallowed (will not throw). So you should only run code that can't throw errors. It may be synchronous only. Note this method will always be called, even if errors were thrown bybefore
orreduce
.inherited -
assertUncompletedFuture(
) → void -
An async reducer (one that returns Future<AppState?>) must never complete without at least
one await, because this may result in state changes being lost. It's up to you to make sure
all code paths in the reducer pass through at least one
await
.inherited -
before(
) → FutureOr< void> -
This is an optional method that may be overridden to run during action
dispatching, before
reduce
. If this method throws an error, thereduce
method will NOT run, but the methodafter
will. It may be synchronous (returningvoid
) ou async (returningFuture<void>
). You should NOT returnFutureOr
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reduce(
) → St? -
The
reduce
method is the action reducer. It may read the action state, the store state, and then return a new state (ornull
if no state change is necessary).override -
reduceWithState(
Store< St> store, St state) → FutureOr<St?> -
Nest state reducers without dispatching another action.
Example: return AddTaskAction(demoTask).reduceWithState(state);
inherited
-
runtimeTypeString(
) → String -
Returns the runtimeType, without the generic part.
inherited
-
setStore(
Store< St> store) → void -
inherited
-
toString(
) → String -
A string representation of this object.
override
-
wrapError(
Object error, StackTrace stackTrace) → Object? -
If any error is thrown by
reduce
orbefore
, you have the chance to further process it by usingwrapError
. 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:inherited -
wrapReduce(
Reducer< St> reduce) → Reducer<St> -
You may wrap the reducer to allow for some pre or post-processing.
For example, if you want to abort an async reducer if the state
changed since when the reducer started:
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- reducer ↔ WaitReducer
-
Works out-of-the-box for most use cases, but you can inject your
own reducer here during your app's initialization, if necessary.
getter/setter pair