Add off method#165
Conversation
|
Great, thanks!
Yes, I was not even sure someone knew that you can remove the event with that function. That is why I removed it and the idea of having a seperate function in the API called removeListener or off is much better. I'm still waiting with implementing it until the discussion progresses a little bit more.
Events are still working for me? Or do you you mean only the removing part here? |
|
So, let me know if I should remove the I think exposing both on and off definitely makes more sense in the long term.
It was not obvious, but evident by reading the source code
So probably I was doing something wrong, don't mind it. |
It's fine, we can leave it in for now, until the event listeners become part of CIP-0030 I'm gonna merge this PR now. Looks good👍🏻 |
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
.nameof the callback to identify which to clear out and 2) Support to remove the callback was removed, while a lonelyremoveListenerfunction was leftSolution
offmethod, based onremoveListener.nameAbout 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
offmethod:When firing it, all the matching callbacks assigned to a given event are removed and cleared from the window event listener.
Other notes
window.cardanoright away, so I decided to return{ remove: () => off() }at theonmethod, which in the end is backwards compatable with the previous version