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

State available in Kino.JS.Live server callbacks.

Properties

Summary

Functions

Stores key-value pairs in the state.

Sends an event to all clients.

Emits an event to processes subscribed to this kino.

Updates smart cell configuration.

Sends an event to a specific client.

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

Types

@type origin() :: nil | term()
@type t() :: %Kino.JS.Live.Context{
  __private__: map(),
  assigns: map(),
  origin: origin()
}

Functions

@spec 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
@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

broadcast_event(ctx, "new_point", %{x: 10, y: 10})
@spec emit_event(t(), term()) :: :ok

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

emit_event(ctx, %{event: :click, counter: 1})
Link to this function

reconfigure_smart_cell(ctx, opts)

View Source
@spec reconfigure_smart_cell(
  t(),
  keyword()
) :: t()

Updates smart cell configuration.

This function allows for re-configuring some of the options that can be specified in smart cell's Kino.JS.Live.init/2.

Note that this function returns the new context, which you should return from the given handler.

Options

  • :editor - note that the smart cell must be initialized with an editor during init. Supported options: :source, :intellisense_node, :visible
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

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

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