Current section

Files

Jump to
lustre src lustre.erl
Raw

src/lustre.erl

-module(lustre).
-compile([no_auto_import, nowarn_unused_vars]).
-export([application/3, element/1, simple/3, start/2]).
-export_type([error/0, app/2]).
-type error() :: element_not_found.
-type app(Model, Msg) :: any() | {gleam_phantom, Model, Msg}.
-spec application(
fun(() -> {GKF, lustre@cmd:cmd(GKG)}),
fun((GKF, GKG) -> {GKF, lustre@cmd:cmd(GKG)}),
fun((GKF) -> lustre@element:element(GKG))
) -> app(GKF, GKG).
application(Field@0, Field@1, Field@2) ->
'./lustre.ffi.mjs':setup(Field@0, Field@1, Field@2).
-spec element(lustre@element:element(GJQ)) -> app(nil, GJQ).
element(Element) ->
Init = fun() -> {nil, lustre@cmd:none()} end,
Update = fun(_, _) -> {nil, lustre@cmd:none()} end,
Render = fun(_) -> Element end,
'.@lustre.ffi.mjs':setup(Init, Update, Render).
-spec simple(
fun(() -> GJU),
fun((GJU, GJV) -> GJU),
fun((GJU) -> lustre@element:element(GJV))
) -> app(GJU, GJV).
simple(Init, Update, Render) ->
Init@1 = fun() -> {Init(), lustre@cmd:none()} end,
Update@1 = fun(Model, Msg) -> {Update(Model, Msg), lustre@cmd:none()} end,
'.@lustre.ffi.mjs':setup(Init@1, Update@1, Render).
-spec start(app(any(), GKA), binary()) -> {ok, fun((GKA) -> nil)} |
{error, error()}.
start(App, Selector) ->
_pipe = '.@lustre.ffi.mjs':start(App, Selector),
gleam@result:replace_error(_pipe, element_not_found).