MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / updateProperties

Function updateProperties

plugins/UiPluginManager/media/js/all.js:367–454  ·  view source on GitHub ↗
(domNode, previousProperties, properties, projectionOptions)

Source from the content-addressed store, hash-verified

365 }
366 };
367 var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
368 if (!properties) {
369 return;
370 }
371 var propertiesUpdated = false;
372 var propNames = Object.keys(properties);
373 var propCount = propNames.length;
374 for (var i = 0; i < propCount; i++) {
375 var propName = propNames[i];
376 // assuming that properties will be nullified instead of missing is by design
377 var propValue = properties[propName];
378 var previousValue = previousProperties[propName];
379 if (propName === 'class') {
380 if (previousValue !== propValue) {
381 throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
382 }
383 } else if (propName === 'classes') {
384 var classList = domNode.classList;
385 var classNames = Object.keys(propValue);
386 var classNameCount = classNames.length;
387 for (var j = 0; j < classNameCount; j++) {
388 var className = classNames[j];
389 var on = !!propValue[className];
390 var previousOn = !!previousValue[className];
391 if (on === previousOn) {
392 continue;
393 }
394 propertiesUpdated = true;
395 if (on) {
396 classList.add(className);
397 } else {
398 classList.remove(className);
399 }
400 }
401 } else if (propName === 'styles') {
402 var styleNames = Object.keys(propValue);
403 var styleCount = styleNames.length;
404 for (var j = 0; j < styleCount; j++) {
405 var styleName = styleNames[j];
406 var newStyleValue = propValue[styleName];
407 var oldStyleValue = previousValue[styleName];
408 if (newStyleValue === oldStyleValue) {
409 continue;
410 }
411 propertiesUpdated = true;
412 if (newStyleValue) {
413 checkStyleValue(newStyleValue);
414 projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
415 } else {
416 projectionOptions.styleApplyer(domNode, styleName, '');
417 }
418 }
419 } else {
420 if (!propValue && typeof previousValue === 'string') {
421 propValue = '';
422 }
423 if (propName === 'value') {
424 if (domNode[propName] !== propValue && domNode['oninput-value'] !== propValue) {

Callers 1

all.jsFile · 0.70

Calls 2

removeMethod · 0.80
checkStyleValueFunction · 0.70

Tested by

no test coverage detected