WatchAction<N extends ReduxNotifier<T>, T> class abstract Redux

TLDR: This action reruns the reduce method whenever a watched provider changes.

This action is handy if you want to add additional properties to the state but you don't want to write an extra ViewProvider / listener for it. It reruns the reduce method and dispatches a WatchUpdateAction whenever a watched provider changes.

Usually, this action is dispatched in the initialAction of a ReduxNotifier.

Override before to implement some logic before the reduce method. It will run only once, when the WatchAction is first dispatched.

All WatchActions are automatically cancelled when the ReduxNotifier is disposed, but you can also cancel them manually by saving the result of the dispatchTakeResult method in a variable and calling WatchActionSubscription.cancel on it.

Similarly to GlobalAction, this action also has access to the Ref so be careful to not produce any unwanted side effects.

Example: class MyNotifier extends ReduxNotifier

@override get initialAction => MyWatchAction(); }

class MyWatchAction extends WatchAction<MyNotifier, MyState> { @override MyState reduce() { final counter = ref.watch(anotherProvider);

return state.copyWith(
  counter: counter,
);

} }

Inheritance
Implemented types

Constructors

WatchAction()

Properties

debugLabel String
The debug label of the action. Override this getter to provide a custom label.
no setterinherited
disposed bool
Whether this Rebuildable is disposed and should be removed.
no setteroverride
hashCode int
The hash code for this object.
no setteroverride
isWidget bool
Whether this Rebuildable is an ElementRebuildable. This is a workaround for the fact that ElementRebuildable is in refena_flutter so we cannot refer it from here.
no setteroverride
notifier → N
Access the notifier to access other notifiers.
no setterinherited
notifierType Type
no setterinherited
ref WatchableRef
Access the Ref. This is a special ref that can watch other providers.
latefinal
refenaId int
The id.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → T
Returns the current state of the notifier.
no setterinherited
trackOrigin bool
Whether the ActionDispatchedEvent should have the ActionDispatchedEvent.debugOriginRef of the origin of the action. This is true by default for better visualization in the tracing page.
no setterinherited

Methods

after() → void
Override this to have some logic after the action is dispatched. This method is called even if before or reduce throws.
inherited
before() → void
See BaseReduxAction.before for documentation.
inherited
compareIdentity(IdReference other) bool
Returns true, if the other reference has the same id.
inherited
dispatch(SynchronousReduxAction<N, T, dynamic> action, {String? debugOrigin}) → T
Dispatches a synchronous action and updates the state. Returns the new state.
inherited
dispatchAsync(AsynchronousReduxAction<N, T, dynamic> action, {String? debugOrigin}) Future<T>
Dispatches an asynchronous action and updates the state. Returns the new state.
inherited
dispatchAsyncTakeResult<R2>(BaseAsyncReduxActionWithResult<N, T, R2> action, {String? debugOrigin}) Future<R2>
Dispatches an asynchronous action and updates the state. Returns only the result of the action.
inherited
dispatchAsyncWithResult<R2>(BaseAsyncReduxActionWithResult<N, T, R2> action, {String? debugOrigin}) Future<(T, R2)>
Dispatches an asynchronous action and updates the state. Returns the new state along with the result of the action.
inherited
dispatchTakeResult<R2>(BaseReduxActionWithResult<N, T, R2> action, {String? debugOrigin}) → R2
Dispatches an action and updates the state. Returns only the result of the action.
inherited
dispatchWithResult<R2>(BaseReduxActionWithResult<N, T, R2> action, {String? debugOrigin}) → (T, R2)
Dispatches an action and updates the state. Returns the new state along with the result of the action.
inherited
dispose() → void
emitMessage(String message) → void
Emits a message to the observer.
inherited
external<T2>(ReduxNotifier<T2> notifier) Dispatcher<ReduxNotifier<T2>, T2>
Use this method to dispatch external actions within an action. This ensures that the dispatched action has the correct debugOrigin.
inherited
internalWrapReduce() → (T, WatchActionSubscription)
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListenerTarget(BaseNotifier notifier) → void
Only for ElementRebuildable. Noop for others. Notifies that a new BaseNotifier is being listened. This should be called within a build method so it can unwatch old notifiers in the next microtask.
override
onDisposeWidget() → void
Only for ElementRebuildable. Noop for others. Allows for further cleanup logic.
override
rebuild(ChangeEvent? changeEvent, RebuildEvent? rebuildEvent) → void
Schedule a rebuild (in the next frame). Optionally pass the changeEvent, or rebuildEvent that triggered the rebuild. The event is consumed by the ViewProviderNotifier that fires the RebuildEvent.
override
reduce() → T
The method that returns the new state. Whenever a watched provider changes, this method is called again.
toString() String
A string representation of this object.
inherited
wrapReduce() → T
Override this to have some logic before and after the reduce method. Specifically, this method is called after before and before after: before -> wrapReduce -> after

Operators

operator ==(Object other) bool
Subclasses should not override this method. It is used internally by WatchableRef.watch.
override