MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / setValueForProperty

Function setValueForProperty

code/third-party/public/app.js:3572–3631  ·  view source on GitHub ↗

* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value

(node, name, value, isCustomComponentTag)

Source from the content-addressed store, hash-verified

3570 * @param {*} value
3571 */
3572function setValueForProperty(node, name, value, isCustomComponentTag) {
3573 var propertyInfo = getPropertyInfo(name);
3574 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
3575 return;
3576 }
3577 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
3578 value = null;
3579 }
3580 // If the prop isn't in the special list, treat it as a simple attribute.
3581 if (isCustomComponentTag || propertyInfo === null) {
3582 if (isAttributeNameSafe(name)) {
3583 var _attributeName = name;
3584 if (value === null) {
3585 node.removeAttribute(_attributeName);
3586 } else {
3587 node.setAttribute(_attributeName, '' + value);
3588 }
3589 }
3590 return;
3591 }
3592 var mustUseProperty = propertyInfo.mustUseProperty;
3593
3594 if (mustUseProperty) {
3595 var propertyName = propertyInfo.propertyName;
3596
3597 if (value === null) {
3598 var type = propertyInfo.type;
3599
3600 node[propertyName] = type === BOOLEAN ? false : '';
3601 } else {
3602 // Contrary to `setAttribute`, object properties are properly
3603 // `toString`ed by IE8/9.
3604 node[propertyName] = value;
3605 }
3606 return;
3607 }
3608 // The rest are treated as attributes with special cases.
3609 var attributeName = propertyInfo.attributeName,
3610 attributeNamespace = propertyInfo.attributeNamespace;
3611
3612 if (value === null) {
3613 node.removeAttribute(attributeName);
3614 } else {
3615 var _type = propertyInfo.type;
3616
3617 var attributeValue = void 0;
3618 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
3619 attributeValue = '';
3620 } else {
3621 // `setAttribute` with objects becomes only `[object]` in IE8/9,
3622 // ('' + value) makes it output the correct toString()-value.
3623 attributeValue = '' + value;
3624 }
3625 if (attributeNamespace) {
3626 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
3627 } else {
3628 node.setAttribute(attributeName, attributeValue);
3629 }

Callers 3

updateCheckedFunction · 0.70
setInitialDOMPropertiesFunction · 0.70
updateDOMPropertiesFunction · 0.70

Calls 4

getPropertyInfoFunction · 0.70
shouldIgnoreAttributeFunction · 0.70
shouldRemoveAttributeFunction · 0.70
isAttributeNameSafeFunction · 0.70

Tested by

no test coverage detected