* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 4588 | * @param {*} value |
| 4589 | */ |
| 4590 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 4591 | var propertyInfo = getPropertyInfo(name); |
| 4592 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 4593 | return; |
| 4594 | } |
| 4595 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 4596 | value = null; |
| 4597 | } |
| 4598 | // If the prop isn't in the special list, treat it as a simple attribute. |
| 4599 | if (isCustomComponentTag || propertyInfo === null) { |
| 4600 | if (isAttributeNameSafe(name)) { |
| 4601 | var _attributeName = name; |
| 4602 | if (value === null) { |
| 4603 | node.removeAttribute(_attributeName); |
| 4604 | } else { |
| 4605 | node.setAttribute(_attributeName, '' + value); |
| 4606 | } |
| 4607 | } |
| 4608 | return; |
| 4609 | } |
| 4610 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 4611 | |
| 4612 | if (mustUseProperty) { |
| 4613 | var propertyName = propertyInfo.propertyName; |
| 4614 | |
| 4615 | if (value === null) { |
| 4616 | var type = propertyInfo.type; |
| 4617 | |
| 4618 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 4619 | } else { |
| 4620 | // Contrary to `setAttribute`, object properties are properly |
| 4621 | // `toString`ed by IE8/9. |
| 4622 | node[propertyName] = value; |
| 4623 | } |
| 4624 | return; |
| 4625 | } |
| 4626 | // The rest are treated as attributes with special cases. |
| 4627 | var attributeName = propertyInfo.attributeName, |
| 4628 | attributeNamespace = propertyInfo.attributeNamespace; |
| 4629 | |
| 4630 | if (value === null) { |
| 4631 | node.removeAttribute(attributeName); |
| 4632 | } else { |
| 4633 | var _type = propertyInfo.type; |
| 4634 | |
| 4635 | var attributeValue = void 0; |
| 4636 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 4637 | attributeValue = ''; |
| 4638 | } else { |
| 4639 | // `setAttribute` with objects becomes only `[object]` in IE8/9, |
| 4640 | // ('' + value) makes it output the correct toString()-value. |
| 4641 | attributeValue = '' + value; |
| 4642 | } |
| 4643 | if (attributeNamespace) { |
| 4644 | node.setAttributeNS(attributeNamespace, attributeName, attributeValue); |
| 4645 | } else { |
| 4646 | node.setAttribute(attributeName, attributeValue); |
| 4647 | } |
no test coverage detected