Packages
lustre
1.3.0
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@event.erl
-module(lustre@event).
-compile(no_auto_import).
-export([on/2, dispatch/1, on_click/1, on_mouse_down/1, on_mouse_up/1, on_mouse_enter/1, on_mouse_leave/1, on_mouse_over/1, on_mouse_out/1, on_keypress/1, on_keydown/1, on_keyup/1, on_input/1, on_check/1, on_submit/1, on_focus/1, on_blur/1]).
-spec on(binary(), fun((gleam@dynamic:dynamic(), fun((FOH) -> nil)) -> nil)) -> lustre@attribute:attribute(FOH).
on(Name, Handler) ->
lustre@attribute:event(Name, Handler).
-spec dispatch(FOJ) -> fun((fun((FOJ) -> nil)) -> nil).
dispatch(Action) ->
fun(Dispatch) -> Dispatch(Action) end.
-spec on_click(fun((fun((FOK) -> nil)) -> nil)) -> lustre@attribute:attribute(FOK).
on_click(Handler) ->
on(<<"click"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_down(fun((fun((FOM) -> nil)) -> nil)) -> lustre@attribute:attribute(FOM).
on_mouse_down(Handler) ->
on(<<"mouseDown"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_up(fun((fun((FOO) -> nil)) -> nil)) -> lustre@attribute:attribute(FOO).
on_mouse_up(Handler) ->
on(<<"mouseUp"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_enter(fun((fun((FOQ) -> nil)) -> nil)) -> lustre@attribute:attribute(FOQ).
on_mouse_enter(Handler) ->
on(<<"mouseEnter"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_leave(fun((fun((FOS) -> nil)) -> nil)) -> lustre@attribute:attribute(FOS).
on_mouse_leave(Handler) ->
on(<<"mouseLeave"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_over(fun((fun((FOU) -> nil)) -> nil)) -> lustre@attribute:attribute(FOU).
on_mouse_over(Handler) ->
on(<<"mouseOver"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_out(fun((fun((FOW) -> nil)) -> nil)) -> lustre@attribute:attribute(FOW).
on_mouse_out(Handler) ->
on(<<"mouseOut"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_keypress(fun((binary(), fun((FOY) -> nil)) -> nil)) -> lustre@attribute:attribute(FOY).
on_keypress(Handler) ->
on(
<<"keyPress"/utf8>>,
fun(E, Dispatch) ->
{ok, Key@1} = case begin
_pipe = E,
(gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))(
_pipe
)
end of
{ok, Key} -> {ok, Key};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"lustre/event"/utf8>>,
function => <<"on_keypress"/utf8>>,
line => 63})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_keydown(fun((binary(), fun((FPA) -> nil)) -> nil)) -> lustre@attribute:attribute(FPA).
on_keydown(Handler) ->
on(
<<"keyDown"/utf8>>,
fun(E, Dispatch) ->
{ok, Key@1} = case begin
_pipe = E,
(gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))(
_pipe
)
end of
{ok, Key} -> {ok, Key};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"lustre/event"/utf8>>,
function => <<"on_keydown"/utf8>>,
line => 71})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_keyup(fun((binary(), fun((FPC) -> nil)) -> nil)) -> lustre@attribute:attribute(FPC).
on_keyup(Handler) ->
on(
<<"keyUp"/utf8>>,
fun(E, Dispatch) ->
{ok, Key@1} = case begin
_pipe = E,
(gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))(
_pipe
)
end of
{ok, Key} -> {ok, Key};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"lustre/event"/utf8>>,
function => <<"on_keyup"/utf8>>,
line => 79})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_input(fun((binary(), fun((FPE) -> nil)) -> nil)) -> lustre@attribute:attribute(FPE).
on_input(Handler) ->
on(
<<"input"/utf8>>,
fun(E, Dispatch) ->
{ok, Value@1} = case begin
_pipe = E,
(gleam@dynamic:field(
<<"target"/utf8>>,
gleam@dynamic:field(
<<"value"/utf8>>,
fun gleam@dynamic:string/1
)
))(_pipe)
end of
{ok, Value} -> {ok, Value};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"lustre/event"/utf8>>,
function => <<"on_input"/utf8>>,
line => 90})
end,
Handler(Value@1, Dispatch)
end
).
-spec on_check(fun((boolean(), fun((FPG) -> nil)) -> nil)) -> lustre@attribute:attribute(FPG).
on_check(Handler) ->
on(
<<"check"/utf8>>,
fun(E, Dispatch) ->
{ok, Value@1} = case begin
_pipe = E,
(gleam@dynamic:field(
<<"target"/utf8>>,
gleam@dynamic:field(
<<"checked"/utf8>>,
fun gleam@dynamic:bool/1
)
))(_pipe)
end of
{ok, Value} -> {ok, Value};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"lustre/event"/utf8>>,
function => <<"on_check"/utf8>>,
line => 98})
end,
Handler(Value@1, Dispatch)
end
).
-spec on_submit(fun((fun((FPI) -> nil)) -> nil)) -> lustre@attribute:attribute(FPI).
on_submit(Handler) ->
on(<<"submit"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_focus(fun((fun((FPK) -> nil)) -> nil)) -> lustre@attribute:attribute(FPK).
on_focus(Handler) ->
on(<<"focus"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_blur(fun((fun((FPM) -> nil)) -> nil)) -> lustre@attribute:attribute(FPM).
on_blur(Handler) ->
on(<<"blur"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).