xeethemescript v0.2.0 XeeThemeScript behaviour
A behaviour module for definition a Xee theme.
Examples
def YourTheme do use XeeThemeScript
# Callbacks
def init, do: %{ids: MapSet.new(), logs: []}
def receive_meta(data, %{host_id: host_id, token: token}) do
{:ok, data}
end
def join(%{ids: ids} = data, id) do
{:ok, %{data | ids: MapSet.put(ids, id)}}
end
def handle_message(data, message, token) do
handle_received(data, message, token)
end
def handle_received(data, received) do
handle_received(data, received, :host)
end
def handle_received(%{logs: logs} = data, received, id) do
{:ok, %{data | logs: [{id, received} | logs]}}
end end
Summary
Callbacks
Invoked when the experiment receives a message from another experiment
Invoked when the experiment receives data from a host
Invoked when the experiment receives data from a participant
Invoked before the experiment is created
Invoked when the theme is loaded or reloaded
Invoked when a participant loads the experiment page
Types
result ::
{:ok, new_state :: term} |
:error |
{:error, reason :: term}
Return values of init/0
, join/2
, and handle_received/*
functions.
Macros
Callbacks
Specs
handle_message(data :: term, message :: term, token :: term) :: result
Invoked when the experiment receives a message from another experiment.
Returning {:ok, new_state}
changes the state to new_state
.
Returning :error
or {:error, reason}
keeps the state.
Specs
handle_received(data :: term, received :: term) :: result
Invoked when the experiment receives data from a host.
Returning {:ok, new_state}
changes the state to new_state
.
Returning :error
or {:error, reason}
keeps the state.
Specs
handle_received(data :: term, received :: term, id :: term) :: result
Invoked when the experiment receives data from a participant.
Returning {:ok, new_state}
changes the state to new_state
.
Returning :error
or {:error, reason}
keeps the state.
Specs
init :: result
Invoked before the experiment is created.
Returning {:ok, new_state}
sets the initial state to new_state
.
Returning :error
or {:error, reason}
fails the creating of experiment.
Specs
install :: :ok | :error | {:error, reason :: term}
Invoked when the theme is loaded or reloaded.
Specs
join(state :: term, id :: term) :: result
Invoked when a participant loads the experiment page.
Returning {:ok, new_state}
changes the state to new_state
.
Returning :error
or {:error, reason}
keeps the state.