-
Gettext is there for
i18ninternationalization &l10nlocalization support -
can auto-extract translations from code
VideologueWeb.Gettextgets generated on Phoenix project creation; used inerror_helper.ex
- different language translations are in
priv/gettextdir; with pre-set Ecto fileerrors.pot& translations inpriv/gettext/en/LC_MESSAGES
-
a broadcast message, Phoenix sends to PubSub system sent to all sockets (this is
fastlaningsince bypasses channels) -
Phoenix Channels provide
interceptfeature allowing channels to intercept broadcast message -
for each
intercept-ed event, ahandle_outclause shall be defined to handle event -
Phoenix would send message to all sockets, each channel processing intercepted message
-
useful while evolving code, with performance price
- used to propagate live changes; with a channel receiving filesystem events & a plug injecting live-reload iframe on every request
-
uses Erlang by default ensuring broadcast works across multiple nodes, requires all machines to be connected as per Erlang Distribution Protocol
-
supports multiple adapters like
Redis Adapter
-
Phoenix Channels are using WebSockets, working with ES6 & other platforms
-
Channels are Transport Agnostic; can use Custom Protocol to support special requirement
is a lib for building rich interactive bi-directional apps without writing custom JS; example
represent a webpage as a function over web state
establishes messages and callbacks to change state
allows browser events such as MouseClick, FormSubmit, KeyPress to send events
- in
router.ex
import Phoenix.LiveView.Router
##
live "/counter", CounterLive
- add
lib/some_web/live/counter.ex
defmodule SomeWeb.CounterLive do
use Phoenix.LiveView
def render(assigns) do
~L"""
<div>
<h1>count: <%= @val %></h1>
<button phx-click="boom" class="alert-danger">BOOM</button>
<button phx-click="dec">-</button>
<button phx-click="inc">+</button>
</div>
"""
end
def mount(_session, socket), do: {:ok, assign(socket, :val, 0)}
def handle_event("inc", _, socket), do: {:noreply, :val, &(&1 + 1)}
def handle_event("dec", _, socket), do: {:noreply, :val, &(&1 - 1)}
end
- with core functions like following, assuming form for new user
...
def render(assigns) do
Phoenix.View.render(SomeWeb.UserView, "new.html", assigns)
end
def mount(_session, socket) do
{
:ok,
assign(socket, changeset: Accounts.change_user(%User{}))
}
end
def handle_event("save", %{"user" => user_params}, socket) do
Accounts.create_user(user_params) |> do_save()
end
defp do_save({:ok, user}) do
{:stop, socket
|> put_flash(:info, "user created")
|> redirect(to: Routes.live_path(socket, UserLive.show, user))}
end
defp do_save({:error, %Ecto.changeset{} = changeset}) do
{:noreply, assign(socket, changeset: changeset)}
end
...
-
custom adapters could be provided to use
-
PubSub doesn't start as part of Endpoint anymore, need to explicitly provide in Supervision Tree
-
provides Telemetry Developers a unified API for metrics dispatch & instrumentation
-
provides a way collecting built-in VM metrics
-
gives a unified theme for consuming & reporting metrics
Telemetry, a dynamic dispatching lib for metrics & instrumentation
Telemetry Poller, allows periodically collection of measurements and dispatch of events
Telemetry Metrics, provides common interface defining metrics
Telemetry Registry, for event declaration, discovery & registration