View Source Kino.JS.Live.Context (Kino v0.12.3)
State available in Kino.JS.Live
server callbacks.
properties
Properties
:assigns
- custom server state kept across callback calls:origin
- an opaque identifier of the client that triggered the given action. It is set inKino.JS.Live.handle_connect/1
andKino.JS.Live.handle_event/3
Link to this section Summary
Functions
Stores key-value pairs in the state.
Sends an event to all clients.
Emits an event to processes subscribed to this kino.
Sends an event to a specific client.
Updates an existing key with the given function in the state.
Link to this section Types
@type origin() :: nil | term()
Link to this section Functions
@spec assign(t(), Enumerable.t()) :: t()
Stores key-value pairs in the state.
examples
Examples
assign(ctx, count: 1, timestamp: DateTime.utc_now())
Sends an event to all clients.
The event is dispatched to the registered JavaScript callback on all connected clients.
examples
Examples
broadcast_event(ctx, "new_point", %{x: 10, y: 10})
Emits an event to processes subscribed to this kino.
Consumers may subscribe to events emitted by the given instance of
Kino.JS.Live
using functions in the Kino.Control
module, such
as Kino.Control.stream/1
.
examples
Examples
emit_event(ctx, %{event: :click, counter: 1})
Sends an event to a specific client.
The event is dispatched to the registered JavaScript callback on the specific connected client.
examples
Examples
send_event(ctx, origin, "new_point", %{x: 10, y: 10})
Updates an existing key with the given function in the state.
examples
Examples
update(ctx, :count, &(&1 + 1))