diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 523feef..ede22b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,16 +29,6 @@ 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: @@ -46,8 +36,7 @@ jobs: 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: | diff --git a/rebar.config b/rebar.config index a27c3ad..f2ecb97 100644 --- a/rebar.config +++ b/rebar.config @@ -2,8 +2,8 @@ {erl_opts, [ debug_info, - warnings_as_errors%, -% warn_missing_spec + warnings_as_errors, + warn_missing_spec ]}. {deps, [ diff --git a/src/arizona_example_app.erl b/src/arizona_example_app.erl index 076b1fb..53e5cdb 100644 --- a/src/arizona_example_app.erl +++ b/src/arizona_example_app.erl @@ -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. diff --git a/src/arizona_example_live_counter.erl b/src/arizona_example_live_counter.erl index eee79fd..c623543 100644 --- a/src/arizona_example_live_counter.erl +++ b/src/arizona_example_live_counter.erl @@ -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, ~"""
@@ -50,31 +55,41 @@ render(Macros0) -> """). -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"""