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

State available in Kino.JS.Live server callbacks.

Properties

Link to this section Summary

Functions

Stores key-value pairs in the state.

Sends an event to the client.

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

Link to this section Types

Specs

origin() :: nil | term()

Specs

t() :: %Kino.JS.Live.Context{
  __private__: map(),
  assigns: map(),
  origin: origin()
}

Link to this section Functions

Specs

assign(t(), Enumerable.t()) :: t()

Stores key-value pairs in the state.

Examples

assign(ctx, count: 1, timestamp: DateTime.utc_now())
Link to this function

broadcast_event(ctx, event, payload \\ nil)

View Source

Specs

broadcast_event(t(), String.t(), term()) :: :ok

Sends an event to the client.

The event is dispatched to the registered JavaScript callback on all connected clients.

Examples

broadcast_event(ctx, "new_point", %{x: 10, y: 10})

Specs

update(t(), term(), (term() -> term())) :: t()

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

Examples

assign(ctx, count: 1, timestamp: DateTime.utc_now())