"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

exports.__esModule = true;
exports.default = void 0;

var _addEventListeners = _interopRequireDefault(require("./addEventListeners"));

var _removeEventListeners = _interopRequireDefault(require("./removeEventListeners"));

function updateEventListeners(el, prevEvents, events) {
  var eventName;

  if (!prevEvents || !events || prevEvents === events) {
    return;
  }

  for (eventName in events) {
    if (prevEvents[eventName] === events[eventName]) {
      continue;
    }

    if (prevEvents[eventName]) {
      (0, _removeEventListeners.default)(el, eventName, prevEvents[eventName]);
    } // Add new event listeners.


    (0, _addEventListeners.default)(el, eventName, events[eventName]);
  }

  for (eventName in prevEvents) {
    if (!events[eventName]) {
      (0, _removeEventListeners.default)(el, eventName, prevEvents[eventName]);
    }
  }
}

var _default = updateEventListeners;
exports.default = _default;