Fantastic content @mikeclark, thanks!
You can pattern match the brightness
key inside the assigns
map. But it’s just a different style of doing the same thing.
def handle_event("up", _, %{assigns: %{brightness: b}}=socket)
when b == 100, do: {:noreply, socket}
def handle_event("up", _, socket)
do: {:noreply, update(socket, :brightness, &(&1 + 10))}
def handle_event("down", _, %{assigns: %{brightness: b}}=socket)
when b == 0, do: {:noreply, socket}
def handle_event("down", _, socket)
do: {:noreply, update(socket, :brightness, &(&1 - 10))}