Packages
lustre
4.6.2
5.7.1
5.7.0
5.6.0
5.5.2
5.5.1
5.5.0
5.4.0
5.3.5
5.3.4
5.3.3
5.3.2
5.3.1
5.3.0
5.2.1
5.2.0
5.1.1
5.1.0
5.0.3
5.0.2
5.0.1
5.0.0
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.6
4.3.5
4.3.4
4.3.3
4.3.2
4.3.1
4.3.0
4.2.6
4.2.5
4.2.4
4.2.3
4.2.2
4.2.1
4.2.0
4.1.8
4.1.7
4.1.6
4.1.5
4.1.4
4.1.3
4.1.2
4.1.1
4.1.0
4.0.0
4.0.0-rc1
4.0.0-rc.2
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.12
3.0.11
3.0.10
3.0.9
3.0.8
3.0.7
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-rc.8
3.0.0-rc.7
3.0.0-rc.6
3.0.0-rc.5
3.0.0-rc.4
3.0.0-rc.3
3.0.0-rc.2
3.0.0-rc.1
2.0.1
2.0.0
1.3.0
1.2.0
1.1.0
1.0.0
Create HTML templates, single page applications, Web Components, and real-time server components in Gleam!
Current section
Files
Jump to
Current section
Files
src/lustre@effect.erl
-module(lustre@effect).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([custom/1, from/1, event/2, none/0, batch/1, map/2, perform/5]).
-export_type([effect/1, actions/1]).
-opaque effect(OIG) :: {effect, list(fun((actions(OIG)) -> nil))}.
-type actions(OIH) :: {actions,
fun((OIH) -> nil),
fun((binary(), gleam@json:json()) -> nil),
fun((gleam@erlang@process:selector(OIH)) -> nil),
gleam@dynamic:dynamic_()}.
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 126).
-spec custom(
fun((fun((OIM) -> nil), fun((binary(), gleam@json:json()) -> nil), fun((gleam@erlang@process:selector(OIM)) -> nil), gleam@dynamic:dynamic_()) -> nil)
) -> effect(OIM).
custom(Run) ->
{effect,
[fun(Actions) ->
Run(
erlang:element(2, Actions),
erlang:element(3, Actions),
erlang:element(4, Actions),
erlang:element(5, Actions)
)
end]}.
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 105).
-spec from(fun((fun((OII) -> nil)) -> nil)) -> effect(OII).
from(Effect) ->
custom(fun(Dispatch, _, _, _) -> Effect(Dispatch) end).
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 117).
-spec event(binary(), gleam@json:json()) -> effect(any()).
event(Name, Data) ->
custom(fun(_, Emit, _, _) -> Emit(Name, Data) end).
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 146).
-spec none() -> effect(any()).
none() ->
{effect, []}.
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 164).
-spec batch(list(effect(OIR))) -> effect(OIR).
batch(Effects) ->
{effect,
(gleam@list:fold(
Effects,
[],
fun(B, _use1) ->
{effect, A} = _use1,
lists:append(B, A)
end
))}.
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 178).
-spec map(effect(OIV), fun((OIV) -> OIX)) -> effect(OIX).
map(Effect, F) ->
{effect,
(gleam@list:map(
erlang:element(2, Effect),
fun(Eff) ->
fun(Actions) ->
Eff(
{actions,
fun(Msg) -> (erlang:element(2, Actions))(F(Msg)) end,
erlang:element(3, Actions),
fun(Selector) ->
(erlang:element(4, Actions))(
gleam_erlang_ffi:map_selector(Selector, F)
)
end,
erlang:element(5, Actions)}
)
end
end
))}.
-file("/home/runner/work/lustre/lustre/src/lustre/effect.gleam", 230).
-spec perform(
effect(OIZ),
fun((OIZ) -> nil),
fun((binary(), gleam@json:json()) -> nil),
fun((gleam@erlang@process:selector(OIZ)) -> nil),
gleam@dynamic:dynamic_()
) -> nil.
perform(Effect, Dispatch, Emit, Select, Root) ->
Actions = {actions, Dispatch, Emit, Select, Root},
gleam@list:each(erlang:element(2, Effect), fun(Eff) -> Eff(Actions) end).