LineaUI.Installer.Js (linea_ui v0.3.0)

Copy Markdown View Source

The edit mix linea_ui.install makes to the app's assets/js/app.js, as a pure function from the file's contents to its new contents.

It imports LineaUI's hooks and spreads them into the hooks option of the LiveSocket, whether that option is an object (hooks: {...colocatedHooks}), a variable (hooks: Hooks) or missing.

Summary

Functions

Whether the file builds a LiveSocket, which the hooks are registered on.

Returns {:ok, js} with the hooks imported and registered, :unchanged when LineaUI's hooks are already registered, or :error when the file has no LiveSocket options or import to anchor on.

Functions

live_socket?(js)

@spec live_socket?(String.t()) :: boolean()

Whether the file builds a LiveSocket, which the hooks are registered on.

register_hooks(js)

@spec register_hooks(String.t()) :: {:ok, String.t()} | :unchanged | :error

Returns {:ok, js} with the hooks imported and registered, :unchanged when LineaUI's hooks are already registered, or :error when the file has no LiveSocket options or import to anchor on.