Hakushi.Live (Hakushi v0.1.0)

Copy Markdown View Source

The on_mount hook of a LiveView with a shared canvas (live), and the app's own changes to a canvas.

live_session :default, on_mount: [Hakushi.Live] do

or, in one LiveView:

on_mount Hakushi.Live

A shared canvas is a session of an Issho room (see Hakushi.Issho): this hook is Issho's (Issho.Live), which takes the room's events in the LiveView's process and gives them to its canvases, so the LiveView needs no handle_info of its own for them. A LiveView that has on_mount Issho.Live already needs no other. A canvas with live in a LiveView without the hook raises, saying so.

Summary

Functions

Makes the app's own change on the canvas canvas of this LiveView: a node of a form, a label set from a menu, a step a job finished. The change goes the way of a person's (the graph, the rules, on_change), to everyone on a shared canvas, and cannot be undone by the people (by is nil).

Downloads the canvas canvas of this LiveView as an image, in the person's browser: format: :png (the default) or :svg, and filename (the canvas's id unless given), without its extension.

Tidies up the canvas canvas of this LiveView, as its tidy up button does: its nodes in layers along their edges (direction: :right or :down, the canvas's layout unless given). The person's browser lays them out, and the new places are a change as any: checked, shared, and undone with ⌘Z.

Functions

change(canvas, change)

@spec change(String.t(), Hakushi.Change.t()) :: :ok

Makes the app's own change on the canvas canvas of this LiveView: a node of a form, a label set from a menu, a step a job finished. The change goes the way of a person's (the graph, the rules, on_change), to everyone on a shared canvas, and cannot be undone by the people (by is nil).

def handle_event("add_table", %{"name" => name}, socket) do
  node = %Hakushi.Node{id: name, type: "table", x: 0, y: 0, data: %{name: name, columns: []}}
  Hakushi.Live.change("schema", Hakushi.Change.add([node]))
  {:noreply, socket}
end

A change the canvas refuses shows its reason on the canvas. From outside the LiveView (a job), change a shared canvas with Hakushi.Issho.change/3.

export(canvas, opts \\ [])

@spec export(String.t(), keyword()) :: :ok

Downloads the canvas canvas of this LiveView as an image, in the person's browser: format: :png (the default) or :svg, and filename (the canvas's id unless given), without its extension.

layout(canvas, opts \\ [])

@spec layout(String.t(), keyword()) :: :ok

Tidies up the canvas canvas of this LiveView, as its tidy up button does: its nodes in layers along their edges (direction: :right or :down, the canvas's layout unless given). The person's browser lays them out, and the new places are a change as any: checked, shared, and undone with ⌘Z.