Skip to content

Commit

Permalink
[BUG #8038] Store the wrapped callback for once listener for each type
Browse files Browse the repository at this point in the history
  • Loading branch information
wittemann committed Jan 28, 2014
1 parent 203acee commit becc8f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
14 changes: 10 additions & 4 deletions framework/source/class/qx/core/MEvent.js
Expand Up @@ -78,7 +78,13 @@ qx.Mixin.define("qx.core.MEvent",
this.removeListener(type, listener, this, capture);
listener.call(self||this, e);
};
listener.$$wrapped_callback = callback;
// check for wrapped callback storage
if (!listener.$$wrapped_callback) {
listener.$$wrapped_callback = {};
}
// store the call for each type in case the listener is
// used for more than one type [BUG #8038]
listener.$$wrapped_callback[type] = callback;

return this.addListener(type, callback, this, capture);
},
Expand All @@ -98,9 +104,9 @@ qx.Mixin.define("qx.core.MEvent",
{
if (!this.$$disposed) {
// special handling for wrapped once listener
if (listener.$$wrapped_callback) {
var callback = listener.$$wrapped_callback;
delete listener.$$wrapped_callback;
if (listener.$$wrapped_callback && listener.$$wrapped_callback[type]) {
var callback = listener.$$wrapped_callback[type];
delete listener.$$wrapped_callback[type];
listener = callback;
}
return this.__Registration.removeListener(this, type, listener, self, capture);
Expand Down
16 changes: 16 additions & 0 deletions framework/source/class/qx/test/core/Object.js
Expand Up @@ -75,6 +75,22 @@ qx.Class.define("qx.test.core.Object",
},


testAddListenerOnceWithSameListener : function()
{
var called = 0;
var listener = function() {
// debugger;
called++;
};
this.addListenerOnce("test", listener);
this.addListenerOnce("test2", listener);
this.fireEvent("test");
this.assertEquals(1, called);
this.fireEvent("test");
this.assertEquals(1, called);
},


testRemoveListenerById : function()
{
var id = this.addListener("testRemoveListenerById", function() {}, this, false);
Expand Down

0 comments on commit becc8f2

Please sign in to comment.