import addEventListeners from './addEventListeners';
import removeEventListeners from './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]) {
      removeEventListeners(el, eventName, prevEvents[eventName]);
    } // Add new event listeners.


    addEventListeners(el, eventName, events[eventName]);
  }

  for (eventName in prevEvents) {
    if (!events[eventName]) {
      removeEventListeners(el, eventName, prevEvents[eventName]);
    }
  }
}

export default updateEventListeners;