-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
api: no apparent way of removing a specific .on() listener #713
Comments
@leonardpauli sorry this has taken me forever, I've been gone on international trips and super stressed out over RAD fixes and headed into launching this new thing soon. You've done your research! Quite good work. You are correct that Would you do me a favor and update the docs? They are wiki/editable at https://github.com/amark/gun/wiki/API which will update the live site. Your idea of having
Which is why I was left with leaving it to You are right this can lead to awkward situations. How do you turn it off before the callback fires (like canceling an event?). This is a good question, but I do want to note that for now (API stability, not causing breaking changes, etc.) we're going to have to say But to address your points, I think we should consider:
Thoughts? For now, gonna say |
TL;DR: no apparent way of removing .on() listener
id = setTimeout(...); clearTimeout(id)
ctx = gun.get('a').on(...); ctx.off()
After digging in the code, .on() is more or less a wrapper for .get(), and passes along relevant args. See line 46. It would be nice to have that in the docs if it's the recommended way of removing specific listeners. Though having the ability to be calling .off() on the return value from .on() seems preferable in many ways (ability to remove listener before its first invocation, imho, "logical" syntax, etc).
This shouldn't require too much change (<10 lines?) if I saw correct (.on -> .get -> Gun.on that returns ev directly and has access to node, therefore adding ref to ev on node + make .off use node.ev.off() if ev exists, otherwise doing the usual).
Could make a PR if this behavior is the expected one.
The text was updated successfully, but these errors were encountered: