-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add a way to remove a single event listener (#20983) #25535
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
Open
ypujante
wants to merge
21
commits into
emscripten-core:main
Choose a base branch
from
ypujante:issue-20983
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−2
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
adeb50b
First pass at implementing #20983
ypujante 4260b0b
Added missing signature
ypujante 6925d65
fixes test failure
ypujante d489b58
Merge remote-tracking branch 'origin/main' into issue-20983
ypujante 9fc8bd1
Merge branch 'main' into issue-20983
ypujante 55d37cf
Merge branch 'main' into issue-20983
ypujante b7b7240
Merge branch 'emscripten-core:main' into issue-20983
ypujante 6583129
Added emscripten_remove_callback to doc
ypujante cdf9b94
Updated Changelog
ypujante 8578fb2
Merge remote-tracking branch 'origin/main' into issue-20983
ypujante 581444b
Automatic rebaseline of codesize expectations. NFC
ypujante 42410ab
Code review
ypujante 5aea670
Merge remote-tracking branch 'origin/main' into issue-20983
ypujante d1b426f
Automatic rebaseline of codesize expectations. NFC
ypujante f7bd5d5
fixed order
ypujante b89401e
Merge remote-tracking branch 'origin/main' into issue-20983
ypujante 1757110
aligning codesize with "main"
ypujante 3f26d5d
code review
ypujante 6afcddb
Merge remote-tracking branch 'origin/main' into issue-20983
ypujante 0b965fe
Automatic rebaseline of codesize expectations. NFC
ypujante 948e60c
rebaseline tests
sbc100 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,54 @@ The ``useCapture`` parameter maps to ``useCapture`` in `EventTarget.addEventLis | |
|
|
||
| Most functions return the result using the type :c:data:`EMSCRIPTEN_RESULT`. Zero and positive values denote success. Negative values signal failure. None of the functions fail or abort by throwing a JavaScript or C++ exception. If a particular browser does not support the given feature, the value :c:data:`EMSCRIPTEN_RESULT_NOT_SUPPORTED` will be returned at the time the callback is registered. | ||
|
|
||
| Unregister function | ||
| ------------------- | ||
|
|
||
| In order to unregister a single event handler callback, call the following function: | ||
|
|
||
| .. code-block:: cpp | ||
| EMSCRIPTEN_RESULT emscripten_html5_remove_event_listener( | ||
| const char *target, // ID of the target HTML element. | ||
| void *userData, // User-defined data (passed to the callback). | ||
| int eventTypeId, // The event type ID (EMSCRIPTEN_EVENT_XXX). | ||
| void *callback // Callback function. | ||
| ); | ||
| The ``target``, ``userData`` and ``callback`` parameters are the same parameters provided in ``emscripten_set_some_callback`` with the only difference being that, since this function applies to all types of callbacks, the type of ``callback`` is ``void *``. | ||
|
|
||
| Note in particular that the value of ``userData`` will need to match with the call that was used to register the callback. If you are having trouble, double check the value of ``userData``. | ||
|
|
||
| The ``eventTypeId`` represents the event type, the same Id received in the callback functions. | ||
|
|
||
| The function returns ``EMSCRIPTEN_RESULT_SUCCESS`` when the event handler callback is removed and ``EMSCRIPTEN_RESULT_INVALID_PARAM`` otherwise. | ||
|
|
||
| .. code-block:: cpp | ||
| // Example | ||
| bool my_mouse_callback_1(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { | ||
| // ... | ||
| } | ||
| bool my_mouse_callback_2(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { | ||
| // ... | ||
| } | ||
| void main() { | ||
| // 1. set callbacks for mouse down and mouse move | ||
| emscripten_set_mousedown_callback("#mydiv", 0, my_mouse_callback_1); | ||
| emscripten_set_mousedown_callback("#mydiv", (void *) 34, my_mouse_callback_2); | ||
| emscripten_set_mousemove_callback("#mydiv", 0, my_mouse_callback_1); | ||
| // 2. remove these callbacks | ||
| emscripten_html5_remove_event_listener("#mydiv", 0, EMSCRIPTEN_EVENT_MOUSEDOWN, my_mouse_callback_1); | ||
| emscripten_html5_remove_event_listener("#mydiv", (void *) 34, EMSCRIPTEN_EVENT_MOUSEDOWN, my_mouse_callback_2); | ||
| emscripten_html5_remove_event_listener("#mydiv", 0, EMSCRIPTEN_EVENT_MOUSEMOVE, my_mouse_callback_1); | ||
|
Collaborator
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. I still don't love the asymmetry to the API design, but I get that adding 30+ |
||
| } | ||
| Callback functions | ||
| ------------------ | ||
|
|
||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.