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

Function setValueForProperty

code/composition/public/app.js:4477–4536  ·  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

4475 * @param {*} value
4476 */
4477function setValueForProperty(node, name, value, isCustomComponentTag) {
4478 var propertyInfo = getPropertyInfo(name);
4479 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
4480 return;
4481 }
4482 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
4483 value = null;
4484 }
4485 // If the prop isn't in the special list, treat it as a simple attribute.
4486 if (isCustomComponentTag || propertyInfo === null) {
4487 if (isAttributeNameSafe(name)) {
4488 var _attributeName = name;
4489 if (value === null) {
4490 node.removeAttribute(_attributeName);
4491 } else {
4492 node.setAttribute(_attributeName, '' + value);
4493 }
4494 }
4495 return;
4496 }
4497 var mustUseProperty = propertyInfo.mustUseProperty;
4498
4499 if (mustUseProperty) {
4500 var propertyName = propertyInfo.propertyName;
4501
4502 if (value === null) {
4503 var type = propertyInfo.type;
4504
4505 node[propertyName] = type === BOOLEAN ? false : '';
4506 } else {
4507 // Contrary to `setAttribute`, object properties are properly
4508 // `toString`ed by IE8/9.
4509 node[propertyName] = value;
4510 }
4511 return;
4512 }
4513 // The rest are treated as attributes with special cases.
4514 var attributeName = propertyInfo.attributeName,
4515 attributeNamespace = propertyInfo.attributeNamespace;
4516
4517 if (value === null) {
4518 node.removeAttribute(attributeName);
4519 } else {
4520 var _type = propertyInfo.type;
4521
4522 var attributeValue = void 0;
4523 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
4524 attributeValue = '';
4525 } else {
4526 // `setAttribute` with objects becomes only `[object]` in IE8/9,
4527 // ('' + value) makes it output the correct toString()-value.
4528 attributeValue = '' + value;
4529 }
4530 if (attributeNamespace) {
4531 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
4532 } else {
4533 node.setAttribute(attributeName, attributeValue);
4534 }

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