View Source Kino.JS.Live.Context (Kino v0.7.0)

State available in Kino.JS.Live server callbacks.

properties

Properties

Link to this section Summary

Functions

Stores key-value pairs in the state.

Sends an event to all clients.

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()
@type t() :: %Kino.JS.Live.Context{
  __private__: map(),
  assigns: map(),
  origin: origin()
}

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())
Link to this function

broadcast_event(ctx, event, payload \\ nil)

View Source
@spec broadcast_event(t(), String.t(), term()) :: :ok

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})
Link to this function

send_event(ctx, client_id, event, payload \\ nil)

View Source
@spec send_event(t(), term(), String.t(), term()) :: :ok

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})
@spec update(t(), term(), (term() -> term())) :: t()

Updates an existing key with the given function in the state.

examples

Examples

update(ctx, :count, &(&1 + 1))