drab v0.4.0 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
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
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.
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
.
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