import actionSetAttribute from './actionSetAttribute';
var nonEntityPropNames = ['children', 'events', 'primitive'];

var filterNonEntityPropNames = function filterNonEntityPropNames(propName) {
  return nonEntityPropNames.indexOf(propName) === -1;
};

function updateAttributes(el, prevProps, props) {
  var propName;

  if (!props || prevProps === props) {
    return;
  }

  for (propName in props) {
    if (!filterNonEntityPropNames(propName)) {
      continue;
    }

    actionSetAttribute(el, props, propName);
  }

  if (prevProps) {
    for (propName in prevProps) {
      if (!filterNonEntityPropNames(propName)) {
        continue;
      }

      if (props[propName] === undefined) {
        el.removeAttribute(propName);
      }
    }
  }
}

export default updateAttributes;