-
Notifications
You must be signed in to change notification settings - Fork 1k
Refactor pushEvent promise handling and document promise support #3763
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,14 +157,18 @@ The above life-cycle callbacks have in-scope access to the following attributes: | |
|
|
||
| * `el` - attribute referencing the bound DOM node | ||
| * `liveSocket` - the reference to the underlying `LiveSocket` instance | ||
| * `pushEvent(event, payload, (reply, ref) => ...)` - method to push an event from the client to the LiveView server | ||
| * `pushEvent(event, payload, (reply, ref) => ...)` - method to push an event from the client to the LiveView server. | ||
| If no callback function is passed, a promise that resolves to the `reply` is returned. | ||
| * `pushEventTo(selectorOrTarget, event, payload, (reply, ref) => ...)` - method to push targeted events from the client | ||
| to LiveViews and LiveComponents. It sends the event to the LiveComponent or LiveView the `selectorOrTarget` is | ||
| defined in, where its value can be either a query selector or an actual DOM element. If the query selector returns | ||
| more than one element it will send the event to all of them, even if all the elements are in the same LiveComponent | ||
| or LiveView. `pushEventTo` supports passing the node element e.g. `this.el` instead of selector e.g. `"#" + this.el.id` | ||
| as the first parameter for target. | ||
| * `handleEvent(event, (payload) => ...)` - method to handle an event pushed from the server | ||
| As there can be multiple targets, if no callback is passed, a promise is returned that matches the return value of | ||
| [`Promise.allSettled()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled#return_value). Individual fulfilled values are of the format `{ reply, ref }`. | ||
| * `handleEvent(event, (payload) => ...)` - method to handle an event pushed from the server. Returns a value that can be passed to `removeHandleEvent` to remove the event handler. | ||
| * `removeHandleEvent(ref)` - method to remove an event handler added via `handleEvent` | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one was not documented, but I think it should be |
||
| * `upload(name, files)` - method to inject a list of file-like objects into an uploader. | ||
| * `uploadTo(selectorOrTarget, name, files)` - method to inject a list of file-like objects into an uploader. | ||
| The hook will send the files to the uploader with `name` defined by [`allow_upload/3`](`Phoenix.LiveView.allow_upload/3`) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One difference between
pushEventandpushEventTois that for pushEvent, we only resolve thereply, but here the fulfilled value is{ ref, reply }. We could map over the values and remove the ref if we want.