Skip to content

Commit

Permalink
add jsDocs for hook examples
Browse files Browse the repository at this point in the history
  • Loading branch information
RodolfoSilva authored and tgroshon committed Oct 31, 2023
1 parent 3982d92 commit 6055ec7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions guides/client/js-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ like this:
Then a hook callback object could be defined and passed to the socket:

```javascript
/**
* @type {Object.<string, import("phoenix_live_view").ViewHook>}
*/
let Hooks = {}
Hooks.PhoneNumber = {
mounted() {
Expand Down Expand Up @@ -281,6 +284,9 @@ For example, to implement infinite scrolling, one can pass the current page usin
And then in the client:

```javascript
/**
* @type {import("phoenix_live_view").ViewHook}
*/
Hooks.InfiniteScroll = {
page() { return this.el.dataset.page },
mounted(){
Expand All @@ -304,6 +310,9 @@ However, the data attribute approach is not a good approach if you need to frequ
And then on the client:

```javascript
/**
* @type {import("phoenix_live_view").ViewHook}
*/
Hooks.Chart = {
mounted(){
this.handleEvent("points", ({points}) => MyChartLib.addPoints(points))
Expand Down
3 changes: 3 additions & 0 deletions lib/phoenix_live_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@ defmodule Phoenix.LiveView do
Replying to a client event:
# JavaScript:
# /**
# * @type {Object.<string, import("phoenix_live_view").ViewHook>}
# */
# let Hooks = {}
# Hooks.ClientHook = {
# mounted() {
Expand Down

0 comments on commit 6055ec7

Please sign in to comment.