Skip to content

Commit

Permalink
Fix -spec(_).s (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira authored Jun 28, 2024
1 parent a59dfe0 commit c4d1590
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,14 @@ jobs:
version-type: strict
version-file: .tool-versions

- name: Restore _build
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: _build
key: "_build-cache-for\
-os-${{runner.os}}\
-otp-${{steps.setup-beam.outputs.otp-version}}\
-rebar3-${{steps.setup-beam.outputs.rebar3-version}}\
-hash-${{hashFiles('rebar.lock')}}"

- name: Restore rebar3's cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cache/rebar3
key: "rebar3-cache-for\
-os-${{runner.os}}\
-otp-${{steps.setup-beam.outputs.otp-version}}\
-rebar3-${{steps.setup-beam.outputs.rebar3-version}}\
-hash-${{hashFiles('rebar.lock')}}"
-rebar3-${{steps.setup-beam.outputs.rebar3-version}}"

- name: Continuous Integration
run: |
Expand Down
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

0 comments on commit c4d1590

Please sign in to comment.