From aa06912214aef304aa5d647424df0e126f3df3a9 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 6 Dec 2018 12:13:18 -0600 Subject: [PATCH] Fixes the order of .on to onEvent, addEventListener, onKeyValue --- map/map-test.js | 33 +++++++++++++++++++++++++++++++++ map/map.js | 12 ++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/map/map-test.js b/map/map-test.js index 500460e..9a0e55c 100644 --- a/map/map-test.js +++ b/map/map-test.js @@ -402,3 +402,36 @@ test("listenTo and stopListening takes a queueName", function(){ CALLS = []; }); + +QUnit.test("on goes onEvent, addEventListener, then onKeyValue", function(){ + var called = []; + var fullSet = canReflect.assignSymbols({ + addEventListener: function(){ + called.push("addEventListener"); + } + },{ + "can.onEvent": function(){ + called.push("onEvent"); + }, + 'can.onKeyValue': function(){ + called.push("onKeyValue"); + } + }) + eventQueue.on.call(fullSet, "event", function(){}); + + QUnit.deepEqual(called, ["onEvent"]); + + called = []; + var addEvent = canReflect.assignSymbols({ + addEventListener: function(){ + called.push("addEventListener"); + } + },{ + 'can.onKeyValue': function(){ + called.push("onKeyValue"); + } + }) + eventQueue.on.call(addEvent, "event", function(){}); + + QUnit.deepEqual(called, ["addEventListener"]); +}); diff --git a/map/map.js b/map/map.js index a60cc20..03b93f5 100644 --- a/map/map.js +++ b/map/map.js @@ -548,12 +548,12 @@ var props = { domEvents.addEventListener(this, eventName, handler, queue); } } else { - if ("addEventListener" in this) { + if (this[onEventSymbol]) { + this[onEventSymbol](eventName, handler, queue); + } else if ("addEventListener" in this) { this.addEventListener(eventName, handler, queue); } else if (this[onKeyValueSymbol]) { canReflect.onKeyValue(this, eventName, handler, queue); - } else if (this[onEventSymbol]) { - this[onEventSymbol](eventName, handler, queue); } else { if (!eventName && this[onValueSymbol]) { canReflect.onValue(this, handler, queue); @@ -593,12 +593,12 @@ var props = { domEvents.removeEventListener(this, eventName, handler, queue); } } else { - if ("removeEventListener" in this) { + if (this[offEventSymbol]) { + this[offEventSymbol](eventName, handler, queue); + } else if ("removeEventListener" in this) { this.removeEventListener(eventName, handler, queue); } else if (this[offKeyValueSymbol]) { canReflect.offKeyValue(this, eventName, handler, queue); - } else if (this[offEventSymbol]) { - this[offEventSymbol](eventName, handler, queue); } else { if (!eventName && this[offValueSymbol]) { canReflect.offValue(this, handler, queue);