View Source Kino.JS.Live.Context (Kino v0.6.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 the 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 the client.

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

examples

Examples

broadcast_event(ctx, "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))