Skip to content

Fix -spec(_).s #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

{erl_opts, [
debug_info,
warnings_as_errors%,
% warn_missing_spec
warnings_as_errors,
warn_missing_spec
]}.

{deps, [
Expand Down
7 changes: 7 additions & 0 deletions src/arizona_example_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
-export([start/2]).
-export([stop/1]).

-spec start(StartType, StartArgs) -> Started
when StartType :: normal,
StartArgs :: [],
Started :: supervisor:startlink_ret().
start(_StartType, _StartArgs) ->
arizona_example_sup:start_link().

-spec stop(State) -> Stopped
when State :: [],
Stopped :: ok.
stop(_State) ->
ok.

Expand Down
47 changes: 31 additions & 16 deletions src/arizona_example_live_counter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
%% arizona_live_view callbacks.
%% --------------------------------------------------------------------

mount(#{assigns := Assigns} = Socket) ->
Count = maps:get(count, Assigns, 0),
{ok, arizona_socket:assign(count, Count, Socket)}.
-spec mount(Socket) -> Mounted
when Socket :: arizona_socket:t(),
Mounted :: {ok, arizona_socket:t()}.
mount(Socket) ->
Count = arizona_socket:get_assign(count, Socket, 0),
{ok, arizona_socket:put_assign(count, Count, Socket)}.

-spec render(Macros) -> Tree
when Macros :: arizona_live_view:macros(),
Tree :: arizona_live_view:tree().
render(Macros0) ->
Macros = Macros0#{
title => maps:get(title, Macros0, ~"Arizona")
},
?ARIZONA_LIVEVIEW(~"""
Title = arizona_live_view:get_macro(title, Macros0, ~"Arizona"),
Macros = arizona_live_view:put_macro(title, Title, Macros0),
?ARIZONA_LIVEVIEW(Macros, ~"""
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -50,31 +55,41 @@ render(Macros0) ->
</html>
""").

handle_event(<<"incr">>, #{}, #{assigns := Assigns} = Socket) ->
Count = maps:get(count, Assigns) + 1,
{noreply, arizona_socket:assign(count, Count, Socket)};
handle_event(<<"decr">>, #{}, #{assigns := Assigns} = Socket) ->
Count = maps:get(count, Assigns) - 1,
{noreply, arizona_socket:assign(count, Count, Socket)}.
-spec handle_event(EventName, Payload, Socket) -> Handled
when EventName :: binary(),
Payload :: arizona:payload(),
Socket :: arizona_socket:t(),
Handled :: {noreply, arizona_socket:t()}.
handle_event(<<"incr">>, _Payload, Socket) ->
Count = arizona_socket:get_assign(count, Socket) + 1,
{noreply, arizona_socket:put_assign(count, Count, Socket)};
handle_event(<<"decr">>, _Payload, Socket) ->
Count = arizona_socket:get_assign(count, Socket) - 1,
{noreply, arizona_socket:put_assign(count, Count, Socket)}.

%% --------------------------------------------------------------------
%% Component functions.
%% --------------------------------------------------------------------

-spec counter(Macros) -> Tree
when Macros :: arizona_live_view:macros(),
Tree :: arizona_live_view:tree().
counter(Macros) ->
?ARIZONA_LIVEVIEW(~s"""
?ARIZONA_LIVEVIEW(Macros, ~s"""
<div :stateful>
<div>Count: {_@count}</div>
<.button event={_@event} text={_@btn_text} />
</div>
""").

-spec button(Macros) -> Tree
when Macros :: arizona_live_view:macros(),
Tree :: arizona_live_view:tree().
button(Macros) ->
?ARIZONA_LIVEVIEW(~s"""
?ARIZONA_LIVEVIEW(Macros, ~s"""
{% NOTE: On this example, :onclick is and expression to be }
{% dynamic. It could be just, e.g., :onclick="incr". }
<button type="button" :onclick={arizona_js:send(_@event)}>
{_@text}
</button>
""").

16 changes: 7 additions & 9 deletions src/arizona_example_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@

-define(SERVER, ?MODULE).

-spec start_link() -> Ret
when Ret :: supervisor:startlink_ret().
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).

%% sup_flags() = #{strategy => strategy(), % optional
%% intensity => non_neg_integer(), % optional
%% period => pos_integer()} % optional
%% child_spec() = #{id => child_id(), % mandatory
%% start => mfargs(), % mandatory
%% restart => restart(), % optional
%% shutdown => shutdown(), % optional
%% type => worker(), % optional
%% modules => modules()} % optional
-spec init(Args) -> Init
when Args :: [],
Init :: {ok, {SupFlags, [ChildSpec]}},
SupFlags :: supervisor:sup_flags(),
ChildSpec :: supervisor:child_spec().
init([]) ->
SupFlags = #{
strategy => one_for_all,
Expand Down
Loading