Current section

Files

Jump to
lustre src lustre.erl
Raw

src/lustre.erl

-module(lustre).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([application/3, element/1, simple/3, component/5, start/3, destroy/1, is_browser/0, is_registered/1]).
-export_type([app/3, error/0]).
-opaque app(HWY, HWZ, HXA) :: app | {gleam_phantom, HWY, HWZ, HXA}.
-type error() :: app_already_started |
app_not_yet_started |
bad_component_name |
component_already_registered |
element_not_found |
not_a_browser.
-spec application(
fun((HXN) -> {HXO, lustre@effect:effect(HXP)}),
fun((HXO, HXP) -> {HXO, lustre@effect:effect(HXP)}),
fun((HXO) -> lustre@element:element(HXP))
) -> app(HXN, HXO, HXP).
application(_, _, _) ->
gleam@dynamic:unsafe_coerce(gleam@dynamic:from(nil)).
-spec element(lustre@element:element(HXB)) -> app(nil, nil, HXB).
element(Element) ->
Init = fun(_) -> {nil, lustre@effect:none()} end,
Update = fun(_, _) -> {nil, lustre@effect:none()} end,
View = fun(_) -> Element end,
application(Init, Update, View).
-spec simple(
fun((HXG) -> HXH),
fun((HXH, HXI) -> HXH),
fun((HXH) -> lustre@element:element(HXI))
) -> app(HXG, HXH, HXI).
simple(Init, Update, View) ->
Init@1 = fun(Flags) -> {Init(Flags), lustre@effect:none()} end,
Update@1 = fun(Model, Msg) -> {Update(Model, Msg), lustre@effect:none()} end,
application(Init@1, Update@1, View).
-spec component(
binary(),
fun(() -> {HXW, lustre@effect:effect(HXX)}),
fun((HXW, HXX) -> {HXW, lustre@effect:effect(HXX)}),
fun((HXW) -> lustre@element:element(HXX)),
gleam@dict:dict(binary(), fun((gleam@dynamic:dynamic_()) -> {ok, HXX} |
{error, list(gleam@dynamic:decode_error())}))
) -> {ok, nil} | {error, error()}.
component(_, _, _, _, _) ->
{ok, nil}.
-spec start(app(HYG, any(), HYI), binary(), HYG) -> {ok, fun((HYI) -> nil)} |
{error, error()}.
start(_, _, _) ->
{error, not_a_browser}.
-spec destroy(app(any(), any(), any())) -> {ok, nil} | {error, error()}.
destroy(_) ->
{ok, nil}.
-spec is_browser() -> boolean().
is_browser() ->
false.
-spec is_registered(binary()) -> boolean().
is_registered(_) ->
false.