You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/client/js-interop.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,12 @@ except for the following LiveView specific options:
24
24
*`uploaders` – a reference to a user-defined uploaders namespace, containing
25
25
client callbacks for client-side direct-to-cloud uploads. See the
26
26
[External uploads guide](external-uploads.md) for details.
27
+
*`rootViewSelector` - the optional CSS selector to scope which root LiveViews to connect.
28
+
Useful when running multiple liveSockets, each connected to a different application.
29
+
See the [Connecting multiple livesockets](#connecting-multiple-livesockets)
30
+
section below for details.
31
+
32
+
a CSS selector to scope which
27
33
28
34
## Debugging client events
29
35
@@ -313,3 +319,42 @@ Hooks.Chart = {
313
319
```
314
320
315
321
*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.
322
+
323
+
324
+
### Connecting multiple liveSockets
325
+
326
+
LiveView allows connecting more than one `liveSocket`, each targeting different HTML nodes. This is useful to
327
+
isolate the development cycle of a subset of the user interface. This means a different Phoenix application hosted
328
+
in a different domain, can fully support an embedded LiveView. Think of it as Nested LiveViews, but instead of
329
+
process-level isolation, it is a service-level isolation.
330
+
331
+
Annotate your root views with a unique HTML attribute or class:
332
+
333
+
```elixir
334
+
# Main application serving a regular LiveView
335
+
use GreatProductWeb.LiveView, container: {:div, "data-app":"root"}
336
+
337
+
# Cats application, which will serve the cats component
338
+
use CatsWeb.LiveView, container: {:div, "data-app":"cats"}
339
+
```
340
+
341
+
And initialise the liveSockets:
342
+
343
+
```javascript
344
+
# Fetch the disconnected render
345
+
let disconnectedCatsHTML =awaitfetch("https://cats.io/live", { credentials:'include' })
0 commit comments