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

Function setValueForProperty

code/dependency-injection/public/app.js:4432–4491  ·  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

4430 * @param {*} value
4431 */
4432function setValueForProperty(node, name, value, isCustomComponentTag) {
4433 var propertyInfo = getPropertyInfo(name);
4434 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
4435 return;
4436 }
4437 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
4438 value = null;
4439 }
4440 // If the prop isn't in the special list, treat it as a simple attribute.
4441 if (isCustomComponentTag || propertyInfo === null) {
4442 if (isAttributeNameSafe(name)) {
4443 var _attributeName = name;
4444 if (value === null) {
4445 node.removeAttribute(_attributeName);
4446 } else {
4447 node.setAttribute(_attributeName, '' + value);
4448 }
4449 }
4450 return;
4451 }
4452 var mustUseProperty = propertyInfo.mustUseProperty;
4453
4454 if (mustUseProperty) {
4455 var propertyName = propertyInfo.propertyName;
4456
4457 if (value === null) {
4458 var type = propertyInfo.type;
4459
4460 node[propertyName] = type === BOOLEAN ? false : '';
4461 } else {
4462 // Contrary to `setAttribute`, object properties are properly
4463 // `toString`ed by IE8/9.
4464 node[propertyName] = value;
4465 }
4466 return;
4467 }
4468 // The rest are treated as attributes with special cases.
4469 var attributeName = propertyInfo.attributeName,
4470 attributeNamespace = propertyInfo.attributeNamespace;
4471
4472 if (value === null) {
4473 node.removeAttribute(attributeName);
4474 } else {
4475 var _type = propertyInfo.type;
4476
4477 var attributeValue = void 0;
4478 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
4479 attributeValue = '';
4480 } else {
4481 // `setAttribute` with objects becomes only `[object]` in IE8/9,
4482 // ('' + value) makes it output the correct toString()-value.
4483 attributeValue = '' + value;
4484 }
4485 if (attributeNamespace) {
4486 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
4487 } else {
4488 node.setAttribute(attributeName, attributeValue);
4489 }

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