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

Function getValueForProperty

code/third-party/public/app.js:3490–3542  ·  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

3488 * Some properties have multiple equivalent values.
3489 */
3490function getValueForProperty(node, name, expected, propertyInfo) {
3491 {
3492 if (propertyInfo.mustUseProperty) {
3493 var propertyName = propertyInfo.propertyName;
3494
3495 return node[propertyName];
3496 } else {
3497 var attributeName = propertyInfo.attributeName;
3498
3499 var stringValue = null;
3500
3501 if (propertyInfo.type === OVERLOADED_BOOLEAN) {
3502 if (node.hasAttribute(attributeName)) {
3503 var value = node.getAttribute(attributeName);
3504 if (value === '') {
3505 return true;
3506 }
3507 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3508 return value;
3509 }
3510 if (value === '' + expected) {
3511 return expected;
3512 }
3513 return value;
3514 }
3515 } else if (node.hasAttribute(attributeName)) {
3516 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3517 // We had an attribute but shouldn't have had one, so read it
3518 // for the error message.
3519 return node.getAttribute(attributeName);
3520 }
3521 if (propertyInfo.type === BOOLEAN) {
3522 // If this was a boolean, it doesn't matter what the value is
3523 // the fact that we have it is the same as the expected.
3524 return expected;
3525 }
3526 // Even if this property uses a namespace we use getAttribute
3527 // because we assume its namespaced name is the same as our config.
3528 // To use getAttributeNS we need the local name which we don't have
3529 // in our config atm.
3530 stringValue = node.getAttribute(attributeName);
3531 }
3532
3533 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3534 return stringValue === null ? expected : stringValue;
3535 } else if (stringValue === '' + expected) {
3536 return expected;
3537 } else {
3538 return stringValue;
3539 }
3540 }
3541 }
3542}
3543
3544/**
3545 * 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