Skip to content

Commit

Permalink
v0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
grych committed Jun 22, 2018
1 parent c61559e commit 296dd15
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
58 changes: 55 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
# CHANGELOG

## v0.8.3
Subscribe and unsubscribe from external topics in a runtime.
Presence.
Updated behaviour of enable disable.

This version brings two useful features: presence and ability to subscribe to topics in the runtime.

### Upgrading from =< 0.8.2

Please ensure you have set `:main_phoenix_app` in your `config.exs`. The way how Drab is searching
for the Phoenix app it is working on, has been changed.

### Subscribe and unsubscribe from external topics in a runtime

Finally, you are not limited to the compile-time topic you’ve set with `broadcasting/1` macro in the
commander. Now you can `subscribe/2` to the external topic, receiving broadcasts sent to it.

```elixir
subscribe(socket, same_action(MyApp.MyController, :index))
subscribe(socket, same_topic("user_#{user_id}"))
```

### Presence

Conveniences for Phoenix.Presence
If configured (it is disabled by default), tracks the user presence on the topic. The following
example shows the number of connected users, live:

```elixir
defmodule MyAppWeb.MyCommander
use Drab.Commander

broadcasting "global"
onconnect :connected
ondisconnect :disconnected

def connected(socket) do
broadcast_html socket, "#number_of_users", Drab.Presence.count_users(socket)
end

def disconnected(_store, _session) do
topic = same_topic("global")
broadcast_html topic, "#number_of_users", Drab.Presence.count_users(topic)
end
end
```

By default, presence map key is set as a browser UUID (which is shamelessly stored in the local
store in the browser), but it may be also any session value. This may be useful, if you have the
`user_id` already in the session, just configure it:

```elixir
config :drab, :presence, id: :user_id
```

### Updated enable/disable when processing behaviour

After launching an event from the page, the control (button) is disable until processing stops.
Now it is even better, as it recognizes previously disabled controls (#146).

## v0.8.2

Expand Down
2 changes: 2 additions & 0 deletions lib/drab/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ defmodule Drab.Config do
get(:main_phoenix_app) || find_app_in_mix_exs()
end

@spec find_app_in_mix_exs :: atom | no_return
defp find_app_in_mix_exs() do
# try to find out the app name in config.exs, in compile time only
with {:ok, pwd} <- Map.fetch(System.get_env(), "PWD"),
Expand Down Expand Up @@ -126,6 +127,7 @@ defmodule Drab.Config do
get(:endpoint) || find_endpoint_in_app_env() || find_endpoint_in_config_exs()
end

@spec endpoint :: atom
defp find_endpoint_in_app_env() do
case app_env() do
[{ep, _}] -> ep
Expand Down

0 comments on commit 296dd15

Please sign in to comment.