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

Function setValueForProperty

code/new-context-api/public/app.js:3700–3759  ·  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

3698 * @param {*} value
3699 */
3700function setValueForProperty(node, name, value, isCustomComponentTag) {
3701 var propertyInfo = getPropertyInfo(name);
3702 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
3703 return;
3704 }
3705 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
3706 value = null;
3707 }
3708 // If the prop isn't in the special list, treat it as a simple attribute.
3709 if (isCustomComponentTag || propertyInfo === null) {
3710 if (isAttributeNameSafe(name)) {
3711 var _attributeName = name;
3712 if (value === null) {
3713 node.removeAttribute(_attributeName);
3714 } else {
3715 node.setAttribute(_attributeName, '' + value);
3716 }
3717 }
3718 return;
3719 }
3720 var mustUseProperty = propertyInfo.mustUseProperty;
3721
3722 if (mustUseProperty) {
3723 var propertyName = propertyInfo.propertyName;
3724
3725 if (value === null) {
3726 var type = propertyInfo.type;
3727
3728 node[propertyName] = type === BOOLEAN ? false : '';
3729 } else {
3730 // Contrary to `setAttribute`, object properties are properly
3731 // `toString`ed by IE8/9.
3732 node[propertyName] = value;
3733 }
3734 return;
3735 }
3736 // The rest are treated as attributes with special cases.
3737 var attributeName = propertyInfo.attributeName,
3738 attributeNamespace = propertyInfo.attributeNamespace;
3739
3740 if (value === null) {
3741 node.removeAttribute(attributeName);
3742 } else {
3743 var _type = propertyInfo.type;
3744
3745 var attributeValue = void 0;
3746 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
3747 attributeValue = '';
3748 } else {
3749 // `setAttribute` with objects becomes only `[object]` in IE8/9,
3750 // ('' + value) makes it output the correct toString()-value.
3751 attributeValue = '' + value;
3752 }
3753 if (attributeNamespace) {
3754 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
3755 } else {
3756 node.setAttribute(attributeName, attributeValue);
3757 }

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