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.
Context
While following the thread cardano-foundation/CIPs#151 I noticed some work was done very recently to support the on() proposal. I also notice a couple of issues with it, being 1) using
.name
of the callback to identify which to clear out and 2) Support to remove the callback was removed, while a lonelyremoveListener
function was leftSolution
off
method, based onremoveListener
.name
About using
.name
:This would only work when the given callback would not be an anonymous function.
Examples:
In order to identify which callback is which, the function reference works fine.
About the
off
method:When firing it, all the matching callbacks assigned to a given event are removed and cleared from the window event listener.
Other notes
window.cardano
right away, so I decided to return{ remove: () => off() }
at theon
method, which in the end is backwards compatable with the previous version