-
Notifications
You must be signed in to change notification settings - Fork 39
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
Feedback on tutorial (from a beginner's perspective) #227
Comments
Just piggybacking here:
I think |
Another oddity: def render(assigns) do
~H"""
<div class="text-center">
<h1 class="text-4xl font-bold text-center"> Counter: <%= @val %> </h1>
<.button phx-click="dec" class="w-20 bg-red-500 hover:bg-red-600">-</.button>
<.button phx-click="inc" class="w-20 bg-green-500 hover:bg-green-600">+</.button>
</div>
"""
end Initial example shows but later (when the template goes in its own file): def render(assigns) do
~H"""
<div class="text-center">
<h1 class="text-4xl font-bold text-center"> Counter: <%= @val %> </h1>
<button phx-click="dec" class={btn("red")}>
-
</button>
<button phx-click="inc" class={btn("green")}>
+
</button>
</div>
"""
end The I think most people will find the |
defmodule CounterWeb.Counter do
use CounterWeb, :live_view
alias Counter.Count
alias Phoenix.PubSub
@topic Count.topic
def mount(_params, _session, socket) do
if connected?(socket) do
# why are we using Counter.PubSub?
# vvvvvvvvvvvvvv this is aliased the same as Phoenix.PubSub
PubSub.subscribe(Counter.PubSub, @topic)
end
{:ok, assign(socket, val: Count.current()) }
end
# ...
end This bit also doesn't make sense. I know that |
def handle_call(:current, _from, count) do
{:reply, count, count}
end defp make_change(count, change) do
new_count = count + change
PubSub.broadcast(Counter.PubSub, topic(), {:count, new_count})
{:reply, new_count, new_count}
end Why is the count value returned twice in these functions? What is edit: found it: https://github.com/dwyl/phoenix-liveview-counter-tutorial/blob/main/lib/counter/application.ex#L16
|
Some of these could be considered more general bits of Elixir trivia (namespacing, etc.). I think with the earlier claim:
It's looking to me like it probably is essential. Maybe there are ways to gently fold (some of) these bits of knowledge into the tutorial. |
And that's all I've got for now. It's a massive effort to mix together this amount of prose and code and I appreciate all the work you've put into it. One thing that impressed me lately is the format of the Svelte tutorial. I don't know if there's an interactive tool like this for Elixir, but I could see the content in this tutorial fitting that kind of format really nicely. I did a little search, but so far I don't see anything that would run the BEAM in wasm or something like that, but it would be really cool if it did. |
We could re-build this tutorial to use https://livebook.dev for more interactivity. 💭 |
@j-n-f
Once you understand this rendering mechanism, and that you are just passing messages (mostly via some hidden websocket) to processes with callbacks working with pattern matching, you are good to go deeper. The philosophy is rather simple compared to other web frameworks. Then indeed, |
Total elixir newbie here (so my ignorance is pretty high, but maybe this is a useful perspective).
I think for people coming from other languages/frameworks it's a bit confusing to mention that the key is
"inc"
. I don't see that key pop up anywhere else after that, or see how the"inc"
value is relevant. It looks like the new state of:val
is already set and sent to the topic. Is it going to callhandle_event("inc", ...)
again? It doesn't look like it, it seems likehandle_info(...)
is going to updateassigns
for all the connected clients.To put the question another way, why should I pass
"inc"
instead of"foo"
?Everything else is clear, but that's the one bit that doesn't make sense.
The text was updated successfully, but these errors were encountered: