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

Bug in MEvent.addListenerOnce() for multiple times call with same args #9627

Open
fortooon opened this issue Feb 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@fortooon
Copy link

commented Feb 15, 2019

Hi,
I found that MEvent.addListenerOnce() has the bug. If I set same handler to one object to process same event multiple times, in result after fire current event only first handler will be removed, others will be a live forever. Reason is that type + this.$$hash key in listener.$$wrapped_callback[type + this.$$hash] = callback; is not unique in such case.

Probably, there is needed __lastUnique helper variable to generate wright key like in qx.event.Manager.js

To Reproduce
You can run simple example based on http://www.qooxdoo.org/current/demobrowser/#widget~Button.html and see in browser console

qx.Class.define("demobrowser.demo.widget.Button",
{
  extend : qx.application.Standalone,

  members :
  {
    main: function()
    {
      this.base(arguments);

      var box = new qx.ui.layout.HBox();
      box.setSpacing(10);

      var container = new qx.ui.container.Composite(box);
      container.setPadding(20);
      this.getRoot().add(container, {left:0,top:0});

      this.addNormalButtons(container);
      
    },

    addNormalButtons : function(container)
    {
      var btn1 = new qx.ui.form.Button("Button A", "icon/22/apps/media-video-player.png");
      container.add(btn1);
      btn1.addListenerOnce("execute", this.onExecute, this);
      // second handler will be a live forever
      btn1.addListenerOnce("execute", this.onExecute, this);
    },    

    onExecute : function()
    { 
      var t1 = new Date();
      console.log("onExecute", t1.getTime());      
    }
  }
});

Expected behavior
On second button click console.log (onExecute) must not be called. But on this example in browser console we can see that every other click ob button will be handled.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser chromium
  • Version 71.0.3578.98

qooxdoo version : 5.0.2

@level420

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

@fortooon Thank you for reporting this issue. It would be great if you could offer a PR to solve the issue.

@level420 level420 added the bug label Feb 15, 2019

fortooon added a commit to fortooon/qooxdoo that referenced this issue Feb 18, 2019

qooxdoo#9627 store listener unique id added in addListenerOnce to rem…
…ove all listeners correctly

Bug in MEvent.addListenerOnce() for multiple times call with same args qooxdoo#9627
@fortooon

This comment has been minimized.

Copy link
Author

commented Feb 18, 2019

@level420 please, check

fortooon added a commit to fortooon/qooxdoo that referenced this issue Feb 19, 2019

store listener unique ids added in addListenerOnce
store listener unique ids added in addListenerOnce to remove all listeners correctly.

Bug in MEvent.addListenerOnce() for multiple times call with same args qooxdoo#9627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.