From d6d02634711dd08e8df7f9f0a68273257a45ca19 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Fri, 28 Jun 2024 00:03:36 +0100 Subject: [PATCH 1/3] Add some specs, as per new constraints (rebar.config) --- rebar.config | 4 ++-- src/arizona_example_app.erl | 7 +++++++ src/arizona_example_live_counter.erl | 17 +++++++++++++++++ src/arizona_example_sup.erl | 16 +++++++--------- 4 files changed, 33 insertions(+), 11 deletions(-) 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..6adce46 100644 --- a/src/arizona_example_live_counter.erl +++ b/src/arizona_example_live_counter.erl @@ -17,10 +17,16 @@ %% arizona_live_view callbacks. %% -------------------------------------------------------------------- +-spec mount(Socket) -> Mounted + when Socket :: arizona_socket:t(), + Mounted :: {ok, arizona_socket:t()}. mount(#{assigns := Assigns} = Socket) -> Count = maps:get(count, Assigns, 0), {ok, arizona_socket: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") @@ -50,6 +56,11 @@ render(Macros0) -> """). +-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">>, #{}, #{assigns := Assigns} = Socket) -> Count = maps:get(count, Assigns) + 1, {noreply, arizona_socket:assign(count, Count, Socket)}; @@ -61,6 +72,9 @@ handle_event(<<"decr">>, #{}, #{assigns := Assigns} = Socket) -> %% Component functions. %% -------------------------------------------------------------------- +-spec counter(Macros) -> Tree + when Macros :: arizona_live_view:macros(), + Tree :: arizona_live_view:tree(). counter(Macros) -> ?ARIZONA_LIVEVIEW(~s"""
@@ -69,6 +83,9 @@ counter(Macros) ->
"""). +-spec button(Macros) -> Tree + when Macros :: arizona_live_view:macros(), + Tree :: arizona_live_view:tree(). button(Macros) -> ?ARIZONA_LIVEVIEW(~s""" {% NOTE: On this example, :onclick is and expression to be } diff --git a/src/arizona_example_sup.erl b/src/arizona_example_sup.erl index 7d8a7e5..6116029 100644 --- a/src/arizona_example_sup.erl +++ b/src/arizona_example_sup.erl @@ -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, From 33956c848b2a5ce688724a56a963fd67eb97d344 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Fri, 28 Jun 2024 00:05:12 +0100 Subject: [PATCH 2/3] Act on newer Arizona interface constraints Expects a recent pull request to be merged: https://github.com/arizona-framework/arizona/pull/104 --- src/arizona_example_live_counter.erl | 30 +++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/arizona_example_live_counter.erl b/src/arizona_example_live_counter.erl index 6adce46..c623543 100644 --- a/src/arizona_example_live_counter.erl +++ b/src/arizona_example_live_counter.erl @@ -20,18 +20,17 @@ -spec mount(Socket) -> Mounted when Socket :: arizona_socket:t(), Mounted :: {ok, arizona_socket:t()}. -mount(#{assigns := Assigns} = Socket) -> - Count = maps:get(count, Assigns, 0), - {ok, arizona_socket:assign(count, Count, Socket)}. +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, ~""" @@ -61,12 +60,12 @@ render(Macros0) -> Payload :: arizona:payload(), Socket :: arizona_socket:t(), Handled :: {noreply, arizona_socket:t()}. -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)}. +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. @@ -76,7 +75,7 @@ handle_event(<<"decr">>, #{}, #{assigns := Assigns} = Socket) -> when Macros :: arizona_live_view:macros(), Tree :: arizona_live_view:tree(). counter(Macros) -> - ?ARIZONA_LIVEVIEW(~s""" + ?ARIZONA_LIVEVIEW(Macros, ~s"""
Count: {_@count}
<.button event={_@event} text={_@btn_text} /> @@ -87,11 +86,10 @@ counter(Macros) -> 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". } """). - From cc7379e45943c08e92805bfa7e5fa0a4b767b748 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Fri, 28 Jun 2024 22:22:19 +0100 Subject: [PATCH 3/3] Fix cache 1. we're not using rebar.lock so it should be part of the key 2. we're always going "bleeding edge", so we shouldn't cache deps --- .github/workflows/ci.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) 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: |