Skip to content

Commit

Permalink
Do not expose yet
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 16, 2024
1 parent 7ba9c38 commit 66e91d1
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions guides/client/js-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,50 +311,3 @@ Hooks.Chart = {
```
*Note*: In case a LiveView pushes events and renders content, `handleEvent` callbacks are invoked after the page is updated. Therefore, if the LiveView redirects at the same time it pushes events, callbacks won't be invoked on the old page's elements. Callbacks would be invoked on the redirected page's newly mounted hook elements.
## Locked DOM elements and loading states
Whenever pushings events to the server, such as a button click or form submission, LiveView locks elements in the DOM and applies CSS based loading states as outlined in the [bindings](bindings.md) guide. The lock consists of a `data-phx-ref` attribute, which prevents any inbound patches from
altering the contents of an element until that ref is acknowledged by the server. This prevents UI race conditions from happenign on the client and provides UI feedback during the round trip.
Custom JavaScript can integrate with the locking events to implement optimistic UI layers, or apply their own custom loading states. The following `CustomEvent`'s are dispatched to an element whenever an event is pushed to the server:
`phx:push` – A push was sent to the server and lock applied to the element for any
phx-binding event. The event `detail` is an object with:
`event` – The name of the `phx-` event, for example `<button phx-click="save">`
would set the event as `"save"`.
`eventType` – The type of event, such as "click", "submit", "change".
`ref` - The lock ref.
`loading` - The list of elements locked with loading classes for this ref.
`lock` – A function which accepts a list of DOM nodes to lock with the same lock
applied to the event's target element. And returns a promise which resolves
when the push has been acknowledged by the server.
`unlock` – A function which accepts a list of DOM nodes to unlock. The lock tracking
attributes are removed, along with the loading state class names.
`getAck` - A function which returns a promise that resolves when the push has been
acknowledged by the server.
`phx:push:[event]` – A specific push for an event was sent and lock applied to the element.
Allows a script to more easily distinguish where a lock originated. Contains the same
attributes as `phx:lock`. For example `<button phx-click="save">` could be listened for via:
this.addEventListener("phx:push:save", ({detail}) => console.log("locked", detail.ref))
`phx:ack` – An acknowledgement was received and lock was removed from the previously locked
element, with the following detail:
`ref` – The lock's ref
`event` – The name of the phx binding event
`phx:ack:[event]` – An acknowledgement was received and lock was removed from the previously
locked element for a given event, with the following detail:
`ref` – The lock's ref.
`event` – The name of the phx binding event

0 comments on commit 66e91d1

Please sign in to comment.