Per-session registry for Drafter.ActionHandler modules.
Handlers are stored in the calling process dictionary and checked in
reverse-registration order (last registered = highest priority).
The built-in handler is always present and handles the standard return values
({:ok, state}, {:noreply, state}, {:show_modal, ...}, {:show_toast, ...},
{:push, ...}, {:pop, ...}, {:replace, ...}).
Usage
Drafter.ActionRegistry.register(MyApp.DrawerHandler)
Drafter.run(MyApp)The register/1 call stores the handler in the calling process's dictionary.
Drafter.run/2 collects them and passes them to the app loop process.
Summary
Functions
The calling process's handler list, highest priority first.
Offer action to each handler in turn and return the resulting state.
Reset the calling process's handler list to extra_handlers plus the built-in one.
Add module to the front of the calling process's handler list.
Functions
@spec collect() :: [module()]
The calling process's handler list, highest priority first.
Returns [] — not the built-in handler — when neither init/1 nor register/1
has run in this process. Drafter.run/2 uses this to copy handlers into the app
loop process.
Offer action to each handler in turn and return the resulting state.
Stops at the first handler returning {:ok, new_state} and returns that state.
Returns acc_state unchanged when every handler returns :unhandled. In a process
where nothing has been registered, only the built-in action handler is consulted.
@spec init([module()]) :: :ok
Reset the calling process's handler list to extra_handlers plus the built-in one.
extra_handlers are checked before the built-in action handler and default to
[]. Any handlers already registered in this process are discarded.
@spec register(module()) :: :ok
Add module to the front of the calling process's handler list.
The most recently registered handler is checked first. Registering the same module twice leaves two entries; the duplicate is harmless but never reached.