LivePanels.Item.Content.LiveView.Commands (livepanels v0.1.0)

Copy Markdown View Source

Socket-first helpers for LivePanels item content.

use LivePanels.Item.Content.LiveView imports these helpers for LiveViews mounted inside a canvas item. Item LiveViews that own mount/3 directly can import this module after calling LivePanels.Item.Content.LiveView.mount_runtime/4.

These helpers dispatch requests to the parent canvas LiveView and return the socket they receive. Helpers without an explicit item id read the current item id from LivePanels.Context; during disconnected mount that id may be absent, so those self-scoped helpers log a debug message and return without dispatching.

notify/3 publishes to another item's topic. request/2 sends a app-defined message to the parent canvas LiveView as {:livepanels_item_request, message}.

Summary

Functions

Requests that the parent canvas add an item of type.

Requests that the parent canvas add an item attached to the current item.

Requests that the parent canvas add an item attached to parent_item_id.

Returns the canvas id for this item content LiveView.

Returns the current item's id, or nil before an item id is assigned.

Requests a props merge for the current item.

Requests a props merge for the item identified by item_id.

Publishes message to the item-scoped topic of another item LiveView.

Requests placement of the current item.

Requests placement of the item identified by item_id.

Requests that the parent canvas present an existing item.

Requests replacement of props on the current item.

Requests replacement of props on the item identified by item_id.

Requests removal of the current item.

Requests removal of the item identified by item_id.

Sends an app-defined request to the parent canvas LiveView.

Types

command_opts()

@type command_opts() :: keyword()

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

Functions

add(socket, type, opts \\ [])

@spec add(socket(), term(), command_opts()) :: socket()

Requests that the parent canvas add an item of type.

opts accepts the same item creation options as LivePanels.Canvas.Item.add/3.

add_attached(socket, type, opts \\ [])

@spec add_attached(socket(), term(), command_opts()) :: socket()

Requests that the parent canvas add an item attached to the current item.

During disconnected mount, the current item id may not be assigned yet; in that case this helper logs a debug message and returns socket without dispatching.

add_attached(socket, parent_item_id, type, opts)

@spec add_attached(socket(), String.t(), term(), command_opts()) :: socket()

Requests that the parent canvas add an item attached to parent_item_id.

canvas_id(socket)

@spec canvas_id(socket()) :: String.t()

Returns the canvas id for this item content LiveView.

item_id(socket)

@spec item_id(socket()) :: String.t() | nil

Returns the current item's id, or nil before an item id is assigned.

merge_props(socket, props)

@spec merge_props(socket(), map()) :: socket()

Requests a props merge for the current item.

During disconnected mount, the current item id may not be assigned yet; in that case this helper logs a debug message and returns socket without dispatching.

merge_props(socket, item_id, props)

@spec merge_props(socket(), String.t(), map()) :: socket()

Requests a props merge for the item identified by item_id.

notify(socket, item_id, message)

@spec notify(socket(), String.t(), term()) :: socket()

Publishes message to the item-scoped topic of another item LiveView.

The receiving item LiveView gets the message in handle_info/2. Item LiveViews are subscribed to their own item topic automatically at mount.

place(socket, placement)

@spec place(socket(), map()) :: socket()

Requests placement of the current item.

During disconnected mount, the current item id may not be assigned yet; in that case this helper logs a debug message and returns socket without dispatching.

place(socket, item_id, placement)

@spec place(socket(), String.t(), map()) :: socket()

Requests placement of the item identified by item_id.

present(socket, item_id, opts \\ [])

@spec present(socket(), String.t(), command_opts()) :: socket()

Requests that the parent canvas present an existing item.

opts accepts the same presentation options as LivePanels.Canvas.Item.present/3.

put_props(socket, props)

@spec put_props(socket(), map()) :: socket()

Requests replacement of props on the current item.

During disconnected mount, the current item id may not be assigned yet; in that case this helper logs a debug message and returns socket without dispatching.

put_props(socket, item_id, props)

@spec put_props(socket(), String.t(), map()) :: socket()

Requests replacement of props on the item identified by item_id.

remove(socket)

@spec remove(socket()) :: socket()

Requests removal of the current item.

During disconnected mount, the current item id may not be assigned yet; in that case this helper logs a debug message and returns socket without dispatching.

remove(socket, item_id)

@spec remove(socket(), String.t()) :: socket()

Requests removal of the item identified by item_id.

request(socket, message)

@spec request(socket(), term()) :: socket()

Sends an app-defined request to the parent canvas LiveView.

The parent receives {:livepanels_item_request, message} in handle_info/2. The runtime does not interpret the payload.