cellium behaviour (cellium v0.1.0)
View SourceThis module defines the cellium behaviour, which is the core of a Cellium application.
It's a gen_server that manages the application's state, event handling, and rendering
loop. To create an application, you must implement the callback functions defined in this
behaviour.
The three main callbacks are:
init/1: To set up the initial state of the application (the model).update/2: To handle events and update the application model.render/1: To define the UI by transforming the model into a widget tree.
A simple application would look like this:
-module(my_app).
-behaviour(cellium).
-export([init/1, update/2, render/1]).
init(_Args) ->
{ok, #{text => <<"Hello, World!">>}}.
update(Model, _Msg) ->
Model.
render(#{text := Text}) ->
text:new(my_text, Text).
Summary
Callbacks
Invoked when the application starts. It should initialize the application's state, referred to as the 'model'.
Takes the current application Model and returns a widget tree (Layout) to be rendered on the screen.
This function defines the UI of the application.
Handles incoming messages and updates the application state.
Msg is the message to process, and Model is the current state. It should return the new state NewModel.
Functions
Sends an event to the application's update/2 callback for processing.
This is the primary way to send messages to the running application.
Starts the Cellium application.
Args is a map containing configuration, including the module that implements the cellium behaviour.
Stops the Cellium application gracefully.
Callbacks
Invoked when the application starts. It should initialize the application's state, referred to as the 'model'.
Takes the current application Model and returns a widget tree (Layout) to be rendered on the screen.
This function defines the UI of the application.
Handles incoming messages and updates the application state.
Msg is the message to process, and Model is the current state. It should return the new state NewModel.
Functions
-spec handle_event(Event :: term()) -> {ok, done}.
Sends an event to the application's update/2 callback for processing.
This is the primary way to send messages to the running application.
Starts the Cellium application.
Args is a map containing configuration, including the module that implements the cellium behaviour.
-spec stop() -> ok.
Stops the Cellium application gracefully.