Releases: grych/drab
Friday Afternoon at the Airport
Phoenix 1.4 compatibility
Drab is now blessed and tested to work with Pheonix 1.4. Plus bugfixes.
Maintenance
This is a maintenance release: few bugfixes.
Cookies and Safe
This is a slow evolution release, containing a number of bug fixes and a few new features:
- Cookies function in
Drab.Browser
iex> set_cookie(socket, "mycookie", "value", max_age: 10)
{:ok, "mycookie=value; expires=Thu, 19 Jul 2018 19:47:09 GMT"}
iex> Drab.Browser.cookies(socket, decoder: Drab.Coder.Cipher)
{:ok, %{"other" => 42, "mycookie" => "value"}}
Drab.{Live, Core, Element, Modal}
functions accept%Phoenix.HTML.Safe{}
That means you don't need to call safe_to_string/1
anymore, just pass the safe:
html = ~E"<strong><%= nick %>:</strong> <%= message %><br>"
broadcast_insert socket, "#chat", :beforeend, html
- Tested with Elixir 1.7
Drab is now blessed to work with Elixir 1.7 and OTP 21.
jQueryless Modal
Drab.Modal
is not dependent on Drab.Query
anymore, and does not require jQuery to run! You
may now use it out of the box, with standard Phoenix installation. Works with both Bootstrap 3
and 4, while Bootstrap 3 is used by default. In case you want to use Bootstrap 4, configure it with:
config :drab, :modal_css, :boostrap4
Drab.Modal
is now loaded by default, as it became the part of Standard Drab Modules.
Also changed the Drab store storage, now it is encrypted, not only signed.
Templates for modal and buttons have been changed!
If you are already using the custom templates for modal of for the button, please read the documentation and update them.
Breaking Release
This release finally introduces the final API. There is no intention to change it, unless very
significant errors are found.
If you are using Drab already, prepare for the changes in the configuration and also in the code.
Drab.Live
API changed
As described in #127, API has changed. The most painful change is Drab.Live.peek
, as it now
returns {:ok, value}
or {:error, why}
. Raising Drab.Live.peek
is for convinience.
Drab.Live.poke
returns tuple now as well, to catch update errors or disconnections.
Redesigned Drab.Config
Since this version, Drab is no longer configured globally. This means that you may use it in the
multiple endpoints environments.
This requires configuration API change. Most of the Drab options are now located under
the endpoint module:
config :drab, MyAppWeb.Endpoint,
otp_app: :my_app_web,
...
The endpoint and application name are mandatory.
However, there are still few global options, like :enable_live_scripts
. Please read
Drab.Config
documentation
for more information.
More API changes
All functions returning {:timeout, description}
now return just {:error, :timeout}
.
Undeclared handler or shared commander raises
All handlers must now be strictly declared by using Drab.Commander.defhandler
or
Drab.Commander.public
macro.
defhandler my_handler(socket, payload), do: ..
or
public :my_handler
def my_handler(socket, payload), do: ...
The same is with shared commanders, if you want to use it, declare it with Drab.Controller
:
use Drab.Controller, commanders: [My.Shared.Commander]
Hard depreciations of various functions
- Drab.Client.js/2
- Drab.run_handler()
- Drab.Browser.console!/2
- Drab.Browser.redirect_to!/2
- Drab.Core.broadcast_js!/2
drab-event
and drab-handler
combination no longer exists
The existing syntax drab-event
and drab-handler
is removed. Please use the new syntax of:
<tag drab="event:handler">
<input drab="focus:input_focus blur:input_blur"
<input drab-focus="input_focus" drab-blur="input_blur">
Updating from <= v0.8.3
config.exs
Replace:
config :drab, main_phoenix_app: :my_app_web, endpoint: MyAppWeb.Endpoint
with:
config :drab, MyAppWeb.Endpoint, otp_app: :my_app_web
Most of the configuration options now must be placed under the endpoint. Please read
Drab.Config
documentation for more info.
v0.8.3 - Subscribe For Your Presence Now
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.
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:
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:
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).
Are we ready for a final API?
This version is a preparation for v0.9.0, which is going to bring API changes, as described in #127.
- new functions in Drab.Element (#134, #135)
- new
Drab.Coder
for encoding terms to string (#137) - new
js_socket_constructor
config (#133), useful when using Drab with Webpack - all assigns are now peekable (#126)
broadcast_poke
now gets subject, not only socket (under some limitations) (#141)- preserve csrf token if
poke
updates the form (fix for #130)
`mix drab.install`
Very important role of Drab is to encourage beginners to try out Elixir |> Phoenix |> Drab
. The
goal is to have an environment, which is less scary than others, like ruby.rails.ajax
. This
is why all the configuration stuff should be minimized (but with options for power users).
mix drab.install
Bug Fixes
Again, Drab.Live
engine has been redesigned to solve existing and future issues.
`rm priv/drab.live.cache`
Potentially breaking release!
Drab.Live
engine has been redesigned again. No more stupid DETS cache anymore. Drab engine now creates modules for each template, and stores metadata compiled there.
Elixir version
Bumped to 1.6, because of the changes in the EEx Engine
Migration from 0.7.7
rm priv/drab.live.cache
mix clean
Bug fixes
Many. See closed issues!