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
* Add JS.to_encodable/1 function for pushing JS commands via events
The new `JS.to_encodable/1` function transforms the
`Phoenix.LiveView.JS` struct into an opaque JSON-serializable value,
such that it can be transmitted outside of HEEx templates.
See discussion https://elixirforum.com/t/make-js-t-a-public-data-structure-or-json-serializable/53870?u=rhcarvalho.
* Conditionally implement Jason.Encoder and JSON.Encoder for Phoenix.LiveView.JS
Makes it more convenient to use JS commands in `push_event` payloads.
* Reword `JS.to_encodable/1` doc
- No need to link to hexdocs.pm, ExDoc will do that automatically
- Use the same wording as Phoenix, "JSON library" instead of "JSON encoder"
- More concise wording
* Add to_encodable/1 tests
* Add Jason.Encoder and JSON.Encoder tests
* Simplify js.exec test
1. Remove done callback, which is meant to be used with
callbacks/asynchronous code.
https://jestjs.io/docs/asynchronous#callbacks
2. Use jest.runAllTimers(), reflecting typical usage when we don't care
about intermediate timer states.
https://jestjs.io/docs/jest-object#jestrunalltimershttps://jestjs.io/docs/jest-object#jestadvancetimersbytimemstorun
* Add JS test coverage for execJS, js().exec and hook.js().exec
* Conditionally define JSON.Encoder test
To avoid warnings on older Elixir versions where JSON.Encoder is not
available.
When the JSON module is not available, we define a skipped test with
the same name for visibility in test reports.
Copy file name to clipboardExpand all lines: guides/client/js-interop.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,8 +34,8 @@ The `liveSocket` instance exposes the following methods:
34
34
-`disableDebug()` - turns off debug logging
35
35
-`enableLatencySim(milliseconds)` - turns on latency simulation, see [Simulating latency](#simulating-latency)
36
36
-`disableLatencySim()` - turns off latency simulation
37
-
-`execJS(el, encodedJS)` - executes encoded JavaScript in the context of the element
38
-
-`js()` - returns an object with methods to manipulate the DOM and execute JavaScript. The applied changes integrate with server DOM patching. See [JS commands](#js-commands).
37
+
-`execJS(el, encodedJS)` - executes encoded JS command in the context of the element
38
+
-`js()` - returns an object with methods to manipulate the DOM and execute JS commands. The applied changes integrate with server DOM patching. See [JS commands](#js-commands).
39
39
40
40
## Debugging client events
41
41
@@ -477,5 +477,5 @@ The command interface returned by `js()` above offers the following functions:
477
477
-`push(el, type, opts = {})` - pushes an event to the server. To target a LiveComponent by its ID, pass a separate `target` in the options. Options: `target`, `loading`, `page_loading`, `value`. For more details, see `Phoenix.LiveView.JS.push/1`.
478
478
-`navigate(href, opts = {})` - sends a navigation event to the server and updates the browser's pushState history. Options: `replace`. For more details, see `Phoenix.LiveView.JS.navigate/1`.
479
479
-`patch(href, opts = {})` - sends a patch event to the server and updates the browser's pushState history. Options: `replace`. For more details, see `Phoenix.LiveView.JS.patch/1`.
480
-
-`exec(encodedJS)` - *only via Client hook `this.js()`*: executes encoded JavaScript in the context of the hook's root node. The encoded JS command should be constructed via `Phoenix.LiveView.JS` and is usually stored as an HTML attribute. Example: `this.js().exec(this.el.getAttribute('phx-remove'))`.
481
-
-`exec(el, encodedJS)` - *only via `liveSocket.js()`*: executes encoded JavaScript in the context of any element.
480
+
-`exec(encodedJS)` - *only via Client hook `this.js()`*: executes encoded JS command in the context of the hook's root node. The encoded JS command should be constructed via `Phoenix.LiveView.JS` and is usually stored as an HTML attribute. Example: `this.js().exec(this.el.getAttribute('phx-remove'))`.
481
+
-`exec(el, encodedJS)` - *only via `liveSocket.js()`*: executes encoded JS command in the context of any element.
0 commit comments