Current section
Files
Jump to
Current section
Files
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((EPT) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EPT).
on(Name, Handler) ->
react_gleam@attribute:event(Name, Handler).
-spec dispatch(EPV) -> fun((fun((EPV) -> nil)) -> nil).
dispatch(Action) ->
fun(Dispatch) -> Dispatch(Action) end.
-spec on_click(fun((fun((EPW) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EPW).
on_click(Handler) ->
on(<<"click"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_down(fun((fun((EPY) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EPY).
on_mouse_down(Handler) ->
on(<<"mouseDown"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_up(fun((fun((EQA) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQA).
on_mouse_up(Handler) ->
on(<<"mouseUp"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_enter(fun((fun((EQC) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQC).
on_mouse_enter(Handler) ->
on(<<"mouseEnter"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_leave(fun((fun((EQE) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQE).
on_mouse_leave(Handler) ->
on(<<"mouseLeave"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_over(fun((fun((EQG) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQG).
on_mouse_over(Handler) ->
on(<<"mouseOver"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_mouse_out(fun((fun((EQI) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQI).
on_mouse_out(Handler) ->
on(<<"mouseOut"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_keypress(fun((binary(), fun((EQK) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQK).
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((EQM) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQM).
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((EQO) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQO).
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((EQQ) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQQ).
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((EQS) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQS).
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((EQU) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQU).
on_submit(Handler) ->
on(<<"submit"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_focus(fun((fun((EQW) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQW).
on_focus(Handler) ->
on(<<"focus"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).
-spec on_blur(fun((fun((EQY) -> nil)) -> nil)) -> react_gleam@attribute:attribute(EQY).
on_blur(Handler) ->
on(<<"blur"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).