Internal action structure for fast pattern matching.
Actions are normalized to this struct internally for consistent handling and optimized pattern matching in the BEAM VM.
Fields
type- Action type identifier (must be a binary string)payload- Action data (any term)meta- Action metadata:async: true- Route to handle_async/3 instead of handle_action/2reducers: [:user, :cart]- List of reducer names (atoms) to target explicitly.- Bypasses normal prefix routing
- Only specified reducers are called
- Action type passed WITHOUT prefix stripping
- Warning logged if reducer doesn't exist
reducer_prefix: "user"- Only call reducers with this prefix (whenreducersnot specified)- Custom metadata for middleware/logging
Usage
Actions are dispatched using the dispatch/4 function:
# Basic action
dispatch(session_id, "user.reload")
# With payload
dispatch(session_id, "user.set", %{id: 123})
# With meta (async) - note: meta is a keyword list
dispatch(session_id, "user.fetch", %{page: 1}, async: true)
# Target specific reducers (bypasses prefix routing, no prefix stripping)
dispatch(session_id, "user.reload", nil, reducers: [:user, :cart])
# → Only :user and :cart called, both receive "user.reload" unchangedReducers pattern match on the normalized Action struct for fast, consistent matching.
Summary
Functions
Check if action should be routed to handle_async/3.
Create an Action struct from type, payload, and meta.
Get reducer prefix filter if specified.
Get list of reducer names this action should be routed to.
Types
Functions
Check if action should be routed to handle_async/3.
Returns true if meta contains async: true.
Create an Action struct from type, payload, and meta.
Type must be a binary string. Payload and meta can be any term.
Examples
iex> Action.new("user.reload", nil, %{})
%Action{type: "user.reload", payload: nil, meta: %{}}
iex> Action.new("user.set", %{id: 123}, %{})
%Action{type: "user.set", payload: %{id: 123}, meta: %{}}
iex> Action.new("fetch", %{page: 1}, %{async: true})
%Action{type: "fetch", payload: %{page: 1}, meta: %{async: true}}
Get reducer prefix filter if specified.
Returns nil if no prefix filter.
Returns string prefix if meta contains reducer_prefix: "user".
Get list of reducer names this action should be routed to.
Returns nil if action should be routed to all reducers.
Returns list of reducer names if meta contains reducers: [...].