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

Function getValueForProperty

code/redux/public/app.js:4508–4560  ·  view source on GitHub ↗

* Get the value for a property on a node. Only used in DEV for SSR validation. * The "expected" argument is used as a hint of what the expected value is. * Some properties have multiple equivalent values.

(node, name, expected, propertyInfo)

Source from the content-addressed store, hash-verified

4506 * Some properties have multiple equivalent values.
4507 */
4508function getValueForProperty(node, name, expected, propertyInfo) {
4509 {
4510 if (propertyInfo.mustUseProperty) {
4511 var propertyName = propertyInfo.propertyName;
4512
4513 return node[propertyName];
4514 } else {
4515 var attributeName = propertyInfo.attributeName;
4516
4517 var stringValue = null;
4518
4519 if (propertyInfo.type === OVERLOADED_BOOLEAN) {
4520 if (node.hasAttribute(attributeName)) {
4521 var value = node.getAttribute(attributeName);
4522 if (value === '') {
4523 return true;
4524 }
4525 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4526 return value;
4527 }
4528 if (value === '' + expected) {
4529 return expected;
4530 }
4531 return value;
4532 }
4533 } else if (node.hasAttribute(attributeName)) {
4534 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4535 // We had an attribute but shouldn't have had one, so read it
4536 // for the error message.
4537 return node.getAttribute(attributeName);
4538 }
4539 if (propertyInfo.type === BOOLEAN) {
4540 // If this was a boolean, it doesn't matter what the value is
4541 // the fact that we have it is the same as the expected.
4542 return expected;
4543 }
4544 // Even if this property uses a namespace we use getAttribute
4545 // because we assume its namespaced name is the same as our config.
4546 // To use getAttributeNS we need the local name which we don't have
4547 // in our config atm.
4548 stringValue = node.getAttribute(attributeName);
4549 }
4550
4551 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4552 return stringValue === null ? expected : stringValue;
4553 } else if (stringValue === '' + expected) {
4554 return expected;
4555 } else {
4556 return stringValue;
4557 }
4558 }
4559 }
4560}
4561
4562/**
4563 * Get the value for a attribute on a node. Only used in DEV for SSR validation.

Callers 1

diffHydratedProperties$1Function · 0.70

Calls 1

shouldRemoveAttributeFunction · 0.70

Tested by

no test coverage detected