drab v0.2.3 Drab.Core
Drab Module with the basic communication from Server to the Browser. Does not require any libraries like jQuery, works on pure Phoenix.
defmodule DrabPoc.JquerylessCommander do
use Drab.Commander, modules: []
def clicked(socket, payload) do
socket |> console("You've sent me this: #{payload |> inspect}")
end
end
See Drab.Commander
for more info on Drab Modules.
Running Elixir code from the Browser
There is the Javascript method Drab.run_handler()
in global Drab
object, which allows you to run the Elixir
function defined in the Commander.
Drab.run_handler(event_name, function_name, arguments_map)
Arguments:
- event_name(string) - name of the even which runs the function
- function_name(string) - function name in corresponding Commander module
- arguments_map(key/value object) - any arguments you want to pass to the Commander function
Returns:
- no return, does not wait for any answer
Summary
Functions
Asynchronously broadcasts given javascript to all browsers displaying current page
Sends the log to the browser console for debugging
Broadcasts the log to the browsers console for debugging
Synchronously executes the given javascript on the client side and returns value
Returns the value of the Drab store represented by the given key
Returns the value of the Drab store represented by the given key or default
when key not found
Returns the socket with the store key => value pair assigned
Functions
Asynchronously broadcasts given javascript to all browsers displaying current page.
Synchronously executes the given javascript on the client side and returns value.
Returns the value of the Drab store represented by the given key.
uid = get_store(socket, :user_id)
Returns the value of the Drab store represented by the given key or default
when key not found
counter = get_store(socket, :counter, 0)