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

Function setValueForProperty

code/styling/public/app.js:4339–4398  ·  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

4337 * @param {*} value
4338 */
4339function setValueForProperty(node, name, value, isCustomComponentTag) {
4340 var propertyInfo = getPropertyInfo(name);
4341 if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
4342 return;
4343 }
4344 if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
4345 value = null;
4346 }
4347 // If the prop isn't in the special list, treat it as a simple attribute.
4348 if (isCustomComponentTag || propertyInfo === null) {
4349 if (isAttributeNameSafe(name)) {
4350 var _attributeName = name;
4351 if (value === null) {
4352 node.removeAttribute(_attributeName);
4353 } else {
4354 node.setAttribute(_attributeName, '' + value);
4355 }
4356 }
4357 return;
4358 }
4359 var mustUseProperty = propertyInfo.mustUseProperty;
4360
4361 if (mustUseProperty) {
4362 var propertyName = propertyInfo.propertyName;
4363
4364 if (value === null) {
4365 var type = propertyInfo.type;
4366
4367 node[propertyName] = type === BOOLEAN ? false : '';
4368 } else {
4369 // Contrary to `setAttribute`, object properties are properly
4370 // `toString`ed by IE8/9.
4371 node[propertyName] = value;
4372 }
4373 return;
4374 }
4375 // The rest are treated as attributes with special cases.
4376 var attributeName = propertyInfo.attributeName,
4377 attributeNamespace = propertyInfo.attributeNamespace;
4378
4379 if (value === null) {
4380 node.removeAttribute(attributeName);
4381 } else {
4382 var _type = propertyInfo.type;
4383
4384 var attributeValue = void 0;
4385 if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
4386 attributeValue = '';
4387 } else {
4388 // `setAttribute` with objects becomes only `[object]` in IE8/9,
4389 // ('' + value) makes it output the correct toString()-value.
4390 attributeValue = '' + value;
4391 }
4392 if (attributeNamespace) {
4393 node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
4394 } else {
4395 node.setAttribute(attributeName, attributeValue);
4396 }

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