Raxol.Plugins.EventHandler.Common (Raxol v2.0.1)

View Source

Common utilities and helper functions for event handling across plugins.

Summary

Functions

Generic dispatcher that reduces over plugins and calls a specific handler function.

Extracts plugin state from a plugin struct.

Handles calling a specific callback on a plugin and processing the result.

Logs an unexpected result from a plugin.

Updates a plugin instance in the manager.

Updates the manager state with a new plugin state.

Types

accumulator()

@type accumulator() :: map()

callback_name()

@type callback_name() :: atom()

event()

@type event() :: map()

manager()

@type manager() :: Raxol.Plugins.Manager.Core.t()

plugin()

@type plugin() :: map()

result_handler_fun()

@type result_handler_fun() :: fun()

Functions

dispatch_event(manager, callback_name, args, required_arity, initial_acc, result_handler)

Generic dispatcher that reduces over plugins and calls a specific handler function.

extract_plugin_state(plugin)

@spec extract_plugin_state(plugin()) :: map()

Extracts plugin state from a plugin struct.

handle_plugin_event(plugin, callback_name, args, required_arity, acc, result_handler)

@spec handle_plugin_event(
  plugin(),
  callback_name(),
  list(),
  non_neg_integer(),
  accumulator(),
  result_handler_fun()
) :: {:cont, accumulator()} | {:halt, accumulator()}

Handles calling a specific callback on a plugin and processing the result.

log_plugin_error(plugin, callback_name, reason)

@spec log_plugin_error(plugin(), callback_name(), term()) :: :ok

Logs an error from a plugin.

log_unexpected_result(plugin, callback_name, result)

@spec log_unexpected_result(plugin(), callback_name(), term()) :: :ok

Logs an unexpected result from a plugin.

update_manager_plugin(manager, old_plugin, updated_plugin)

@spec update_manager_plugin(Raxol.Plugins.Manager.Core.t(), plugin(), plugin()) ::
  Raxol.Plugins.Manager.Core.t()

Updates a plugin instance in the manager.

update_manager_state(manager, plugin, new_plugin_state)

@spec update_manager_state(Raxol.Plugins.Manager.Core.t(), plugin(), map()) ::
  Raxol.Plugins.Manager.Core.t()

Updates the manager state with a new plugin state.