20
20
-spec mount (Socket ) -> Mounted
21
21
when Socket :: arizona_socket :t (),
22
22
Mounted :: {ok , arizona_socket :t ()}.
23
- mount (#{ assigns : = Assigns } = Socket ) ->
24
- Count = maps : get (count , Assigns , 0 ),
25
- {ok , arizona_socket :assign (count , Count , Socket )}.
23
+ mount (Socket ) ->
24
+ Count = arizona_socket : get_assign (count , Socket , 0 ),
25
+ {ok , arizona_socket :put_assign (count , Count , Socket )}.
26
26
27
27
-spec render (Macros ) -> Tree
28
28
when Macros :: arizona_live_view :macros (),
29
29
Tree :: arizona_live_view :tree ().
30
30
render (Macros0 ) ->
31
- Macros = Macros0 #{
32
- title => maps :get (title , Macros0 , ~ " Arizona" )
33
- },
34
- ? ARIZONA_LIVEVIEW (~ """
31
+ Title = arizona_live_view :get_macro (title , Macros0 , ~ " Arizona" ),
32
+ Macros = arizona_live_view :put_macro (title , Title , Macros0 ),
33
+ ? ARIZONA_LIVEVIEW (Macros , ~ """
35
34
<!DOCTYPE html>
36
35
<html lang="en">
37
36
<head>
@@ -61,12 +60,12 @@ render(Macros0) ->
61
60
Payload :: arizona :payload (),
62
61
Socket :: arizona_socket :t (),
63
62
Handled :: {noreply , arizona_socket :t ()}.
64
- handle_event (<<" incr" >>, #{}, #{ assigns : = Assigns } = Socket ) ->
65
- Count = maps : get (count , Assigns ) + 1 ,
66
- {noreply , arizona_socket :assign (count , Count , Socket )};
67
- handle_event (<<" decr" >>, #{}, #{ assigns : = Assigns } = Socket ) ->
68
- Count = maps : get (count , Assigns ) - 1 ,
69
- {noreply , arizona_socket :assign (count , Count , Socket )}.
63
+ handle_event (<<" incr" >>, _Payload , Socket ) ->
64
+ Count = arizona_socket : get_assign (count , Socket ) + 1 ,
65
+ {noreply , arizona_socket :put_assign (count , Count , Socket )};
66
+ handle_event (<<" decr" >>, _Payload , Socket ) ->
67
+ Count = arizona_socket : get_assign (count , Socket ) - 1 ,
68
+ {noreply , arizona_socket :put_assign (count , Count , Socket )}.
70
69
71
70
% % --------------------------------------------------------------------
72
71
% % Component functions.
@@ -76,7 +75,7 @@ handle_event(<<"decr">>, #{}, #{assigns := Assigns} = Socket) ->
76
75
when Macros :: arizona_live_view :macros (),
77
76
Tree :: arizona_live_view :tree ().
78
77
counter (Macros ) ->
79
- ? ARIZONA_LIVEVIEW (~s """
78
+ ? ARIZONA_LIVEVIEW (Macros , ~s """
80
79
<div :stateful>
81
80
<div>Count: {_@count}</div>
82
81
<.button event={_@event} text={_@btn_text} />
@@ -87,11 +86,10 @@ counter(Macros) ->
87
86
when Macros :: arizona_live_view :macros (),
88
87
Tree :: arizona_live_view :tree ().
89
88
button (Macros ) ->
90
- ? ARIZONA_LIVEVIEW (~s """
89
+ ? ARIZONA_LIVEVIEW (Macros , ~s """
91
90
{% NOTE: On this example, :onclick is and expression to be }
92
91
{% dynamic. It could be just, e.g., :onclick="incr". }
93
92
<button type="button" :onclick={arizona_js:send(_@event)}>
94
93
{_@text}
95
94
</button>
96
95
""" ).
97
-
0 commit comments