Skip to main content

ReduxAction

Every action you create must extend ReduxAction, which comes with a lot of useful fields, methods, and mixins, listed below.

This list may look long, but don't worry. You already learned the important ones in the Basics, and those are enough to be productive.

 

So why the long list? App development is complex, and AsyncRedux aims to cover a wide range of real situations. Other state management tools may offer fewer features, but then you have to solve those problems on your own, which is difficult. AsyncRedux, instead, asks how it can help you, and offers solutions that work great because they are tightly integrated with the tool itself.

Most important ones are:

  • state - Returns current state in the store. This is a getter, and can change after every await, for async actions.
  • reduce - The action reducer that returns the new state. Must be overridden.
  • dispatch - Dispatches an action (sync or async).
  • dispatchAndWait - Dispatches an action and returns a Future that resolves when it finishes.
  • isWaiting - Checks if one or more async actions are currently being processed.
  • isFailed - Returns true if an action failed with a UserException.

Useful ones are:

  • store - Returns the store instance.
  • before - Overridable method that runs before reduce during action dispatching.
  • after - Overridable method that runs after reduce during action dispatching.
  • wrapError - Overridable method that catches or modifies errors thrown by reduce or before methods.
  • dispatchAndWaitAll - Dispatches multiple actions in parallel and waits for all to finish.
  • dispatchAll - Dispatches multiple actions in parallel.
  • dispatchSync - Dispatches a sync action, throws if the action is async.
  • exceptionFor - Returns the UserException of the action that failed.
  • clearExceptionFor - Removes the given action type from the failed actions list.
  • waitCondition - Returns a future that completes when the given state condition is true.
  • waitAllActions - Returns a future that completes when all given actions finish.
  • status - Returns the current status of the action (waiting, failed, completed, etc.).
  • prop - Gets a property from the store (timers, streams, etc.).
  • setProp - Sets a property in the store.
  • disposeProp - Disposes a single property by its key.
  • disposeProps - Disposes all or selected properties (timers, streams, futures).
  • env - Gets the store environment, useful for global values scoped to the store.
  • microtask - Returns a future that completes in the next microtask.
  • assertUncompletedFuture - Asserts that an async reducer has at least one await.
  • initialState - Action getter that hols the state as it was when the action was dispatched. This does NOT change.

Useful mixins:

  • CheckInternet - Checks if there is internet before running the action, shows dialog if not.
  • NoDialog - Used with CheckInternet to turn off the dialog when there is no internet.
  • AbortWhenNoInternet - Silently aborts the action if there is no internet.
  • UnlimitedRetryCheckInternet - Retries indefinitely with internet checking, prevents reentrant dispatches.
  • NonReentrant - Prevents the action from being dispatched if it's already running.
  • Retry - Retries the action if it fails, with configurable delays and max retries.
  • UnlimitedRetries - Used with Retry to retry indefinitely.
  • Debounce - Delays action execution until after a period of inactivity.
  • Throttle - Ensures the action is dispatched at most once per throttle period.
  • OptimisticCommand - Applies state changes optimistically, rolls back on error.
  • OptimisticSync - Optimistic updates with coalescing; merges rapid dispatches into one sync.
  • OptimisticSyncWithPush - Like OptimisticSync but with revision tracking for server pushes.
  • ServerPush - Handles server-pushed updates for OptimisticSyncWithPush.

Finally, these are one-offs for special cases: