drab v0.4.1 Drab.Waiter

Enables Drab Waiter functionality - synchronous wait for browser events in the Commander handler function.

Introduces DSL for register events. Syntax:

waiter(socket) do
  on "selector1", "event_name", fn (sender) ->
  end
  on "selector2", "event_name", fn (sender) ->
  end 
  on_timeout 5000, fn -> end
end

Requires Drab.Query.

Summary

Functions

Callback implementation for Drab.js_templates/0

Callback implementation for Drab.prerequisites/0

Macros

Registers Javascript event_name on selector in the Drab Waiter loop. When the main loop is launched, Drab freezes the current function process and starts waiting for the events. When event occurs, it matches it and runs the corresponding lambda

Register timeout event in Drab Waiter loop. Launches anonymous function after given time (in milliseconds). When no timeout is given, Waiter will wait forever

Main Waiter loop

Functions

js_templates()

Callback implementation for Drab.js_templates/0.

prerequisites()

Callback implementation for Drab.prerequisites/0.

Macros

on(selector, event_name, function)

Registers Javascript event_name on selector in the Drab Waiter loop. When the main loop is launched, Drab freezes the current function process and starts waiting for the events. When event occurs, it matches it and runs the corresponding lambda.

Example:

ret = waiter(socket) do
  on "#button1", "click", fn(sender) -> sender["text"] end
  on "#input1", "keyup", fn(sender) -> sender["val"] end
end

Lambda receives sender: the same Map as the Event Handler does, known there are dom_sender.

on_timeout(timeout, function)

Register timeout event in Drab Waiter loop. Launches anonymous function after given time (in milliseconds). When no timeout is given, Waiter will wait forever.

Example:

ret = waiter(socket) do
  on "#button1", "click", fn(sender) -> sender["text"] end
  on_timeout 5000, fn() -> "timed out" end
end
waiter(socket, list)

Main Waiter loop.

Takes socket as an argument, returns the return value of the function which matched the selector and event.

Inside the do block you may register Browser Events which Waiter will react to. See Drab.Waiter.on.