@enact/core
Advanced tools
Comparing version 2.0.0-beta.1 to 2.0.0-beta.2
@@ -5,2 +5,8 @@ # Change Log | ||
## [2.0.0-beta.2] - 2018-05-07 | ||
### Fixed | ||
- `core/dispatcher.on` to not add duplicate event handlers | ||
## [2.0.0-beta.1] - 2018-04-29 | ||
@@ -7,0 +13,0 @@ |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
var _listeners = require("./listeners"); | ||
@@ -65,3 +65,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var name = ev.type; | ||
var listeners = (0, _listeners.default)(ev.currentTarget, name); | ||
var listeners = (0, _listeners.getListeners)(ev.currentTarget, name); | ||
@@ -74,3 +74,3 @@ if (listeners) { | ||
/** | ||
* Adds a new global event listener | ||
* Adds a new global event listener. Duplicate event handlers will be discarded. | ||
* | ||
@@ -91,6 +91,5 @@ * @function | ||
if (target) { | ||
var listeners = (0, _listeners.default)(target, name); | ||
var length = listeners.push(fn); | ||
var added = (0, _listeners.addListener)(target, name, fn); | ||
if (length === 1) { | ||
if (added && (0, _listeners.getListeners)(target, name).length === 1) { | ||
target.addEventListener(name, dispatcher); | ||
@@ -119,3 +118,3 @@ } | ||
if (target) { | ||
var listeners = (0, _listeners.default)(target, name); | ||
var listeners = (0, _listeners.getListeners)(target, name); | ||
var index = listeners.indexOf(fn); | ||
@@ -122,0 +121,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.getListeners = exports.default = void 0; | ||
exports.addListener = exports.getListeners = exports.default = void 0; | ||
// Simple Map polyfill mapping targets to a hash of names->handler[] | ||
@@ -24,3 +24,16 @@ var targets = []; | ||
exports.getListeners = getListeners; | ||
var addListener = function addListener(target, name, fn) { | ||
var listeners = getListeners(target, name); | ||
if (listeners.indexOf(fn) === -1) { | ||
listeners.push(fn); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
exports.addListener = addListener; | ||
var _default = getListeners; | ||
exports.default = _default; |
@@ -23,2 +23,13 @@ "use strict"; | ||
}); | ||
it('should not register duplicate handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should unregister handlers on target', function () { | ||
@@ -25,0 +36,0 @@ var handler = _sinon.default.spy(); |
{ | ||
"name": "@enact/core", | ||
"version": "2.0.0-beta.1", | ||
"version": "2.0.0-beta.2", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157098
4074