Skip to content

Commit

Permalink
Merge branch 'main' into fix_typo_in_phoenix_components_section
Browse files Browse the repository at this point in the history
  • Loading branch information
BrooklinJazz authored Jul 20, 2023
2 parents 2c52640 + 3787b6b commit f6af040
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions exercises/genserver_drills.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ It should:

* Define a `State.get/1` function that uses [GenServer.call/3](https://hexdocs.pm/elixir/GenServer.html#call/3) and a [GenServer.handle_call/3](https://hexdocs.pm/elixir/GenServer.html#handle_call/3) callback function to retrieve state.
* Define a `State.set/2` function that uses [GenServer.cast/2](https://hexdocs.pm/elixir/GenServer.html#cast/2) and a [GenServer.handle_cast/2](https://hexdocs.pm/elixir/GenServer.html#handle_cast/2) callback function to update state.
* Define a `State.start_link/3` function with a [GenServer.init/1](https://hexdocs.pm/elixir/GenServer.html#c:init/1) callback function to initialize the [GenServer](https://hexdocs.pm/elixir/GenServer.html) with a configurable state.
* Define a `State.start_link/1` function with a [GenServer.init/1](https://hexdocs.pm/elixir/GenServer.html#c:init/1) callback function to initialize the [GenServer](https://hexdocs.pm/elixir/GenServer.html) with a configurable state.

Manually test each function (`State.set/2`, `State.get/1` and `State.start_link/3`) to confirm they work as expected.
Manually test each function (`State.set/2`, `State.get/1` and `State.start_link/1`) to confirm they work as expected.

<details style="background-color: lightgreen; padding: 1rem; margin: 1rem 0;">
<summary>Example Solution</summary>
Expand All @@ -159,6 +159,18 @@ Manually test each function (`State.set/2`, `State.get/1` and `State.start_link/
defmodule State do
use GenServer

def start_link(state) do
GenServer.start_link(__MODULE__, state)
end

def set(pid, new_state) do
GenServer.cast(pid, {:set, new_state})
end

def get(pid) do
GenServer.call(pid, :get)
end

@impl true
def init(state) do
{:ok, state}
Expand All @@ -174,18 +186,6 @@ defmodule State do
# response is not specified
{:reply, state, state}
end

def start_link(state) do
GenServer.start_link(pid, state)
end

def set(pid, new_state) do
GenServer.cast(pid, {:set, new_state})
end

def get(pid) do
GenServer.call(pid, :get)
end
end

{:ok, pid} = State.start_link("initial state")
Expand Down
2 changes: 1 addition & 1 deletion exercises/phoenix_follow_along_counter_app.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Add the link to the template in `counter_web/controllers/counter_html/count.html
<h1 class="text-4xl">The current count is: <%= @count %></h1>

<.link
navigate={~p"/?count=#{to_number(@count) + 1}"}
navigate={~p"/?count=#{@count + 1}"}
class="inline-block p-4 mt-4 text-2xl rounded-full bg-cyan-500 hover:bg-cyan-400"
>
Increment
Expand Down
2 changes: 1 addition & 1 deletion reading/exunit.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ defmodule StringContainsTest do

test "string contains hello" do
string = "hello world"
string =~ "hello"
assert string =~ "hello"
end
end

Expand Down
2 changes: 1 addition & 1 deletion reading/mix.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ on HexDocs. Sometimes removing the `_build` folder and recompiling a project can

Other developers create open-source Elixir projects hosted on GitHub, which we can add as dependencies to our project.

There is a massive ecosystem of Elixir projects to that you don't have to
There is a massive ecosystem of Elixir projects, which means you don't have to
reinvent the wheel and solve already solved problems. The [Hex.pm](https://hex.pm/) contains a list of available Elixir projects you may find useful. For a curated list, check out the [awesome-elixir](https://github.com/h4cc/awesome-elixir) project.

To install a dependency, include the name of the project and desired version in a tuple inside the `deps/0` function
Expand Down
2 changes: 1 addition & 1 deletion reading/supervisors.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The same is true if we manually exit a process using [Process.exit/2](https://he
# Process.exit(pid, :exit)
```

If you would like to learn more about fault taulerance and error handling, Joe Armstrong created an incredible video on the subject.
If you would like to learn more about fault tolerance and error handling, Joe Armstrong created an incredible video on the subject.

<!-- livebook:{"attrs":{"source":"YouTube.new(\"https://www.youtube.com/watch?v=ZOsvgwOR6G0&ab_channel=KentComputing\")","title":"Erlang Master Class 2: Video 3 - Handling errors"},"chunks":null,"kind":"Elixir.HiddenCell","livebook_object":"smart_cell"} -->

Expand Down

0 comments on commit f6af040

Please sign in to comment.