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

Function getValueForProperty

code/new-context-api/public/app.js:3618–3670  ·  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

3616 * Some properties have multiple equivalent values.
3617 */
3618function getValueForProperty(node, name, expected, propertyInfo) {
3619 {
3620 if (propertyInfo.mustUseProperty) {
3621 var propertyName = propertyInfo.propertyName;
3622
3623 return node[propertyName];
3624 } else {
3625 var attributeName = propertyInfo.attributeName;
3626
3627 var stringValue = null;
3628
3629 if (propertyInfo.type === OVERLOADED_BOOLEAN) {
3630 if (node.hasAttribute(attributeName)) {
3631 var value = node.getAttribute(attributeName);
3632 if (value === '') {
3633 return true;
3634 }
3635 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3636 return value;
3637 }
3638 if (value === '' + expected) {
3639 return expected;
3640 }
3641 return value;
3642 }
3643 } else if (node.hasAttribute(attributeName)) {
3644 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3645 // We had an attribute but shouldn't have had one, so read it
3646 // for the error message.
3647 return node.getAttribute(attributeName);
3648 }
3649 if (propertyInfo.type === BOOLEAN) {
3650 // If this was a boolean, it doesn't matter what the value is
3651 // the fact that we have it is the same as the expected.
3652 return expected;
3653 }
3654 // Even if this property uses a namespace we use getAttribute
3655 // because we assume its namespaced name is the same as our config.
3656 // To use getAttributeNS we need the local name which we don't have
3657 // in our config atm.
3658 stringValue = node.getAttribute(attributeName);
3659 }
3660
3661 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
3662 return stringValue === null ? expected : stringValue;
3663 } else if (stringValue === '' + expected) {
3664 return expected;
3665 } else {
3666 return stringValue;
3667 }
3668 }
3669 }
3670}
3671
3672/**
3673 * 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