Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSDoc for hook examples #3022

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1667,6 +1667,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