Skip to content
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

Support removing multiple handlers from an event with client.off #68

Open
neemski opened this issue Jul 12, 2018 · 2 comments
Open

Support removing multiple handlers from an event with client.off #68

neemski opened this issue Jul 12, 2018 · 2 comments

Comments

@neemski
Copy link

neemski commented Jul 12, 2018

Hello!

Why exactly is the handler a required parameter to the off method in client.js? Sometimes you don't have the exact reference to the handler in memory and this can be problematic. Other times, you would just like to clean every handler up too, and in this case we should be able to call something like:

client.off('myEvent');

No?

@neemski neemski changed the title Handler should be optional in client.off Support removing multiple handlers from an event with client.off Jul 12, 2018
@neemski
Copy link
Author

neemski commented Jul 20, 2018

Hi, can I get an update on this? This is really affecting the way we clean up handlers when we switch between ticket_sidebar and user_sidebar apps. Aka, when switching between those apps (on app.activated and app.deactivated), I'd like to bind/clean up all handlers without keeping reference to each bound handler.

For reference, my use case looks like this (using the app_scaffold):

// legacy_app.js
let App = {

  events: {
    'app.activated': 'activateHandler',
    'app.deactivated': 'deactivateHandler',
  },

  activateHandler: function() {
    this.handlerList = [
      {
        evtName: 'myEvent',
        callback: this.myEventHandler,
      },
      ...
    ];

    this.handlerList.forEach((handler) => {
      this.zafClient.on(handler.evtName, handler.callback);
    });
  },

  deactivateHandler: function() {
    // Would be really nice if I could just do
    // this.zafClient.off();
    // But I'll even settle for:
    this.handlerList.forEach((handler) => {
      // Note that this.zafClient.off(handler.evtName, handler.callback); doesn't work
      this.zafClient.off(handler.evtName);
    });
  },

  myEventHandler: function() {
    // ...
  },

  ...

};

export default BaseApp.extend(App);

/cc @danielbreves @Mehul-Porwal

@danielbreves
Copy link
Contributor

Hi @kneem, we don't have plans to implement this at the moment, but I don't see any issues with the idea itself. As this project is open-source you're free to submit a pull request. We'll review and merge as soon as time allows. Thanks, Daniel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants