Current section

Files

Jump to
lustre src lustre@event.erl
Raw

src/lustre@event.erl

-module(lustre@event).
-compile([no_auto_import, nowarn_unused_vars]).
-export([on/2, 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_check/1, on_submit/1, on_focus/1, on_blur/1, value/1, on_input/1, checked/1, mouse_position/1]).
-spec on(binary(), fun((gleam@dynamic:dynamic(), fun((GFQ) -> nil)) -> nil)) -> lustre@attribute:attribute(GFQ).
on(Name, Handler) ->
lustre@attribute:event(Name, Handler).
-spec on_click(GFS) -> lustre@attribute:attribute(GFS).
on_click(Msg) ->
on(<<"click"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_down(GFU) -> lustre@attribute:attribute(GFU).
on_mouse_down(Msg) ->
on(<<"mouseDown"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_up(GFW) -> lustre@attribute:attribute(GFW).
on_mouse_up(Msg) ->
on(<<"mouseUp"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_enter(GFY) -> lustre@attribute:attribute(GFY).
on_mouse_enter(Msg) ->
on(<<"mouseEnter"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_leave(GGA) -> lustre@attribute:attribute(GGA).
on_mouse_leave(Msg) ->
on(<<"mouseLeave"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_over(GGC) -> lustre@attribute:attribute(GGC).
on_mouse_over(Msg) ->
on(<<"mouseOver"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_mouse_out(GGE) -> lustre@attribute:attribute(GGE).
on_mouse_out(Msg) ->
on(<<"mouseOut"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_keypress(fun((binary()) -> GGG)) -> lustre@attribute:attribute(GGG).
on_keypress(Msg) ->
on(<<"keyPress"/utf8>>, fun(Event, Dispatch) -> _pipe = Event,
_pipe@1 = (gleam@dynamic:field(
<<"key"/utf8>>,
fun gleam@dynamic:string/1
))(_pipe),
_pipe@2 = gleam@result:map(_pipe@1, Msg),
_pipe@3 = gleam@result:map(_pipe@2, Dispatch),
gleam@result:unwrap(_pipe@3, nil) end).
-spec on_keydown(fun((binary()) -> GGI)) -> lustre@attribute:attribute(GGI).
on_keydown(Msg) ->
on(<<"keyDown"/utf8>>, fun(Event, Dispatch) -> _pipe = Event,
_pipe@1 = (gleam@dynamic:field(
<<"key"/utf8>>,
fun gleam@dynamic:string/1
))(_pipe),
_pipe@2 = gleam@result:map(_pipe@1, Msg),
_pipe@3 = gleam@result:map(_pipe@2, Dispatch),
gleam@result:unwrap(_pipe@3, nil) end).
-spec on_keyup(fun((binary()) -> GGK)) -> lustre@attribute:attribute(GGK).
on_keyup(Msg) ->
on(<<"keyUp"/utf8>>, fun(Event, Dispatch) -> _pipe = Event,
_pipe@1 = (gleam@dynamic:field(
<<"key"/utf8>>,
fun gleam@dynamic:string/1
))(_pipe),
_pipe@2 = gleam@result:map(_pipe@1, Msg),
_pipe@3 = gleam@result:map(_pipe@2, Dispatch),
gleam@result:unwrap(_pipe@3, nil) end).
-spec on_check(fun((boolean()) -> GGO)) -> lustre@attribute:attribute(GGO).
on_check(Msg) ->
on(<<"change"/utf8>>, fun(Event, Dispatch) -> _pipe = Event,
_pipe@1 = (gleam@dynamic:field(
<<"target"/utf8>>,
gleam@dynamic:field(
<<"checked"/utf8>>,
fun gleam@dynamic:bool/1
)
))(_pipe),
_pipe@2 = gleam@result:map(_pipe@1, Msg),
_pipe@3 = gleam@result:map(_pipe@2, Dispatch),
gleam@result:unwrap(_pipe@3, nil) end).
-spec on_submit(GGQ) -> lustre@attribute:attribute(GGQ).
on_submit(Msg) ->
on(<<"submit"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_focus(GGS) -> lustre@attribute:attribute(GGS).
on_focus(Msg) ->
on(<<"focus"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec on_blur(GGU) -> lustre@attribute:attribute(GGU).
on_blur(Msg) ->
on(<<"blur"/utf8>>, fun(_, Dispatch) -> Dispatch(Msg) end).
-spec value(gleam@dynamic:dynamic()) -> {ok, binary()} |
{error, list(gleam@dynamic:decode_error())}.
value(Event) ->
_pipe = Event,
(gleam@dynamic:field(
<<"target"/utf8>>,
gleam@dynamic:field(<<"value"/utf8>>, fun gleam@dynamic:string/1)
))(_pipe).
-spec on_input(fun((binary()) -> GGM)) -> lustre@attribute:attribute(GGM).
on_input(Msg) ->
on(<<"change"/utf8>>, fun(Event, Dispatch) -> _pipe = Event,
_pipe@1 = value(_pipe),
_pipe@2 = gleam@result:map(_pipe@1, Msg),
_pipe@3 = gleam@result:map(_pipe@2, Dispatch),
gleam@result:unwrap(_pipe@3, nil) end).
-spec checked(gleam@dynamic:dynamic()) -> {ok, boolean()} |
{error, list(gleam@dynamic:decode_error())}.
checked(Event) ->
_pipe = Event,
(gleam@dynamic:field(
<<"target"/utf8>>,
gleam@dynamic:field(<<"checked"/utf8>>, fun gleam@dynamic:bool/1)
))(_pipe).
-spec mouse_position(gleam@dynamic:dynamic()) -> {ok, {float(), float()}} |
{error, list(gleam@dynamic:decode_error())}.
mouse_position(Event) ->
gleam@result:then(
(gleam@dynamic:field(<<"clientX"/utf8>>, fun gleam@dynamic:float/1))(
Event
),
fun(X) ->
gleam@result:then(
(gleam@dynamic:field(
<<"clientY"/utf8>>,
fun gleam@dynamic:float/1
))(Event),
fun(Y) -> {ok, {X, Y}} end
)
end
).