Dala.Plugin.Event (dala v0.3.1)

Copy Markdown View Source

Typed event definitions for Dala plugins.

Provides a type-safe event system with compile-time field validation and efficient binary encoding for the native bridge.

Defining Events

Events are defined inside component blocks:

component "chart" do
  event :zoom, %{x: :f32, y: :f32}
  event :pan, %{x: :f32, y: :f32}
end

This generates a struct module at YourPlugin.Chart.Events.Zoom with typed fields and validation.

Event Struct

The generated struct contains:

  • Fields declared in the event definition
  • __event_name__/0 — returns the event atom
  • __event_fields__/0 — returns list of field names
  • __event_types__/0 — returns map of field name to type

Encoding

Events are encoded as binary for the native bridge using opcode 0xF2.

Summary

Functions

Returns the fully-qualified module name for an event struct.

Creates the AST for an event struct module definition.

Returns the event name as a string.

Creates a new event definition.

Types

t()

@type t() :: %Dala.Plugin.Event{fields: keyword(), module: module(), name: atom()}

Functions

event_module_name(name, parent)

@spec event_module_name(atom(), module()) :: atom()

Returns the fully-qualified module name for an event struct.

expand(name, fields, parent)

@spec expand(atom(), keyword() | map(), module()) :: Macro.t()

Creates the AST for an event struct module definition.

This is meant to be called at compile time inside a __before_compile__ callback.

name_string(event)

@spec name_string(t()) :: String.t()

Returns the event name as a string.

new(name, fields \\ [], module \\ nil)

@spec new(atom(), keyword(), module()) :: t()

Creates a new event definition.