Current section

Files

Jump to
react_gleam src react_gleam@event.erl
Raw

src/react_gleam@event.erl

-module(react_gleam@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((FOK) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOK).
on(Name, Handler) ->
react_gleam@attribute:event(Name, Handler).
-spec dispatch(FOM) -> fun((fun((FOM) -> nil)) -> nil).
dispatch(Action) ->
fun(Dispatch) -> Dispatch(Action) end.
-spec on_click(fun((fun((FON) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FON).
on_click(Handler) ->
on(<<"click"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_down(fun((fun((FOP) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOP).
on_mouse_down(Handler) ->
on(<<"mouseDown"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_up(fun((fun((FOR) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOR).
on_mouse_up(Handler) ->
on(<<"mouseUp"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_enter(fun((fun((FOT) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOT).
on_mouse_enter(Handler) ->
on(<<"mouseEnter"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_leave(fun((fun((FOV) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOV).
on_mouse_leave(Handler) ->
on(<<"mouseLeave"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_over(fun((fun((FOX) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOX).
on_mouse_over(Handler) ->
on(<<"mouseOver"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_out(fun((fun((FOZ) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FOZ).
on_mouse_out(Handler) ->
on(<<"mouseOut"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_keypress(fun((binary(), fun((FPB) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPB).
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 => <<"react_gleam/event"/utf8>>,
function => <<"on_keypress"/utf8>>,
line => 74})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_keydown(fun((binary(), fun((FPD) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPD).
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 => <<"react_gleam/event"/utf8>>,
function => <<"on_keydown"/utf8>>,
line => 89})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_keyup(fun((binary(), fun((FPF) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPF).
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 => <<"react_gleam/event"/utf8>>,
function => <<"on_keyup"/utf8>>,
line => 104})
end,
Handler(Key@1, Dispatch)
end
).
-spec on_input(fun((binary(), fun((FPH) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPH).
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 => <<"react_gleam/event"/utf8>>,
function => <<"on_input"/utf8>>,
line => 122})
end,
Handler(Value@1, Dispatch)
end
).
-spec on_check(fun((boolean(), fun((FPJ) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPJ).
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 => <<"react_gleam/event"/utf8>>,
function => <<"on_check"/utf8>>,
line => 137})
end,
Handler(Value@1, Dispatch)
end
).
-spec on_submit(fun((fun((FPL) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPL).
on_submit(Handler) ->
on(<<"submit"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_focus(fun((fun((FPN) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPN).
on_focus(Handler) ->
on(<<"focus"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_blur(fun((fun((FPP) -> nil)) -> nil)) -> react_gleam@attribute:attribute(FPP).
on_blur(Handler) ->
on(<<"blur"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).