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

Function getValueForProperty

code/dependency-injection/public/app.js:4350–4402  ·  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

4348 * Some properties have multiple equivalent values.
4349 */
4350function getValueForProperty(node, name, expected, propertyInfo) {
4351 {
4352 if (propertyInfo.mustUseProperty) {
4353 var propertyName = propertyInfo.propertyName;
4354
4355 return node[propertyName];
4356 } else {
4357 var attributeName = propertyInfo.attributeName;
4358
4359 var stringValue = null;
4360
4361 if (propertyInfo.type === OVERLOADED_BOOLEAN) {
4362 if (node.hasAttribute(attributeName)) {
4363 var value = node.getAttribute(attributeName);
4364 if (value === '') {
4365 return true;
4366 }
4367 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4368 return value;
4369 }
4370 if (value === '' + expected) {
4371 return expected;
4372 }
4373 return value;
4374 }
4375 } else if (node.hasAttribute(attributeName)) {
4376 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4377 // We had an attribute but shouldn't have had one, so read it
4378 // for the error message.
4379 return node.getAttribute(attributeName);
4380 }
4381 if (propertyInfo.type === BOOLEAN) {
4382 // If this was a boolean, it doesn't matter what the value is
4383 // the fact that we have it is the same as the expected.
4384 return expected;
4385 }
4386 // Even if this property uses a namespace we use getAttribute
4387 // because we assume its namespaced name is the same as our config.
4388 // To use getAttributeNS we need the local name which we don't have
4389 // in our config atm.
4390 stringValue = node.getAttribute(attributeName);
4391 }
4392
4393 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4394 return stringValue === null ? expected : stringValue;
4395 } else if (stringValue === '' + expected) {
4396 return expected;
4397 } else {
4398 return stringValue;
4399 }
4400 }
4401 }
4402}
4403
4404/**
4405 * 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