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

Function setValueForProperty

code/communication/public/app.js:4374–4433  ·  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

4372 * @param {*} value
4373 */
4374function setValueForProperty(node, name, value, isCustomComponentTag) {
4375 var propertyInfo = getPropertyInfo(name);
4376 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
4377 return;
4378 }
4379 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
4380 value = null;
4381 }
4382 // If the prop isn't in the special list, treat it as a simple attribute.
4383 if (isCustomComponentTag || propertyInfo === null) {
4384 if (isAttributeNameSafe(name)) {
4385 var _attributeName = name;
4386 if (value === null) {
4387 node.removeAttribute(_attributeName);
4388 } else {
4389 node.setAttribute(_attributeName, '' + value);
4390 }
4391 }
4392 return;
4393 }
4394 var mustUseProperty = propertyInfo.mustUseProperty;
4395
4396 if (mustUseProperty) {
4397 var propertyName = propertyInfo.propertyName;
4398
4399 if (value === null) {
4400 var type = propertyInfo.type;
4401
4402 node[propertyName] = type === BOOLEAN ? false : '';
4403 } else {
4404 // Contrary to `setAttribute`, object properties are properly
4405 // `toString`ed by IE8/9.
4406 node[propertyName] = value;
4407 }
4408 return;
4409 }
4410 // The rest are treated as attributes with special cases.
4411 var attributeName = propertyInfo.attributeName,
4412 attributeNamespace = propertyInfo.attributeNamespace;
4413
4414 if (value === null) {
4415 node.removeAttribute(attributeName);
4416 } else {
4417 var _type = propertyInfo.type;
4418
4419 var attributeValue = void 0;
4420 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
4421 attributeValue = '';
4422 } else {
4423 // `setAttribute` with objects becomes only `[object]` in IE8/9,
4424 // ('' + value) makes it output the correct toString()-value.
4425 attributeValue = '' + value;
4426 }
4427 if (attributeNamespace) {
4428 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
4429 } else {
4430 node.setAttribute(attributeName, attributeValue);
4431 }

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