vaderjs 1.7.2 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +25 -39
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -406,57 +406,50 @@ export class Component {
|
|
|
406
406
|
}
|
|
407
407
|
Reconciler = {
|
|
408
408
|
update: (oldElement, newElement) => {
|
|
409
|
-
if (!oldElement || !newElement)
|
|
410
|
-
|
|
411
|
-
// If nodes are the same type and can be updated
|
|
409
|
+
if (!oldElement || !newElement)
|
|
410
|
+
return;
|
|
412
411
|
if (this.Reconciler.shouldUpdate(oldElement, newElement)) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
oldElement.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
// Update the parent content (if text content differs)
|
|
412
|
+
console.log(oldElement, newElement)
|
|
413
|
+
if (oldElement.attributes && Object.keys(oldElement.attributes).length > 0)
|
|
414
|
+
Array.from(oldElement.attributes).forEach(({ name }) => {
|
|
415
|
+
if (!newElement.hasAttribute(name)) {
|
|
416
|
+
oldElement.removeAttribute(name);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
if (newElement.attributes && Object.keys(newElement.attributes).length > 0)
|
|
420
|
+
Array.from(newElement.attributes).forEach(({ name, value }) => {
|
|
421
|
+
if (oldElement.getAttribute(name) !== value) {
|
|
422
|
+
oldElement.setAttribute(name, value);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
427
425
|
if (oldElement.childNodes.length === 1 && oldElement.firstChild.nodeType === Node.TEXT_NODE) {
|
|
428
426
|
if (oldElement.textContent !== newElement.textContent) {
|
|
429
427
|
oldElement.textContent = newElement.textContent;
|
|
430
428
|
}
|
|
431
|
-
return;
|
|
429
|
+
return;
|
|
430
|
+
}else if(oldElement.nodeType === Node.TEXT_NODE){
|
|
431
|
+
if (oldElement.textContent !== newElement.textContent) {
|
|
432
|
+
oldElement.textContent = newElement.textContent;
|
|
433
|
+
}
|
|
434
|
+
return;
|
|
432
435
|
}
|
|
433
|
-
|
|
434
|
-
// Reconcile child nodes
|
|
435
436
|
const oldChildren = Array.from(oldElement.childNodes);
|
|
436
437
|
const newChildren = Array.from(newElement.childNodes);
|
|
437
|
-
|
|
438
438
|
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
439
|
-
for (let i = 0;
|
|
439
|
+
for (let i = 0;i < maxLength; i++) {
|
|
440
440
|
if (i >= oldChildren.length) {
|
|
441
|
-
// Add new children
|
|
442
441
|
const newChildClone = newChildren[i].cloneNode(true);
|
|
443
442
|
oldElement.appendChild(newChildClone);
|
|
444
|
-
|
|
445
|
-
// Transfer events for the new child
|
|
446
443
|
const newChildEvents = this.eventRegistry.get(newChildren[i]) || [];
|
|
447
444
|
newChildEvents.forEach(({ type, handler }) => {
|
|
448
445
|
this.addEventListener(newChildClone, type, handler);
|
|
449
446
|
});
|
|
450
447
|
} else if (i >= newChildren.length) {
|
|
451
|
-
// Remove extra old children
|
|
452
448
|
oldElement.removeChild(oldChildren[i]);
|
|
453
449
|
} else {
|
|
454
|
-
// Update existing children recursively
|
|
455
450
|
this.Reconciler.update(oldChildren[i], newChildren[i]);
|
|
456
451
|
}
|
|
457
452
|
}
|
|
458
|
-
|
|
459
|
-
// Reapply events to the parent
|
|
460
453
|
const parentEvents = this.eventRegistry.get(newElement) || [];
|
|
461
454
|
parentEvents.forEach(({ type, handler }) => {
|
|
462
455
|
this.addEventListener(oldElement, type, handler);
|
|
@@ -464,30 +457,23 @@ export class Component {
|
|
|
464
457
|
} else {
|
|
465
458
|
const oldChildren = Array.from(oldElement.childNodes);
|
|
466
459
|
const newChildren = Array.from(newElement.childNodes);
|
|
467
|
-
|
|
468
460
|
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
469
|
-
for (let i = 0;
|
|
461
|
+
for (let i = 0;i < maxLength; i++) {
|
|
470
462
|
if (i >= oldChildren.length) {
|
|
471
|
-
// Add new children
|
|
472
463
|
const newChildClone = newChildren[i].cloneNode(true);
|
|
473
464
|
oldElement.appendChild(newChildClone);
|
|
474
|
-
|
|
475
|
-
// Transfer events for the new child
|
|
476
465
|
const newChildEvents = this.eventRegistry.get(newChildren[i]) || [];
|
|
477
466
|
newChildEvents.forEach(({ type, handler }) => {
|
|
478
467
|
this.addEventListener(newChildClone, type, handler);
|
|
479
468
|
});
|
|
480
469
|
} else if (i >= newChildren.length) {
|
|
481
|
-
// Remove extra old children
|
|
482
470
|
oldElement.removeChild(oldChildren[i]);
|
|
483
|
-
} else {
|
|
484
|
-
// Update existing children recursively
|
|
471
|
+
} else {
|
|
485
472
|
this.Reconciler.update(oldChildren[i], newChildren[i]);
|
|
486
473
|
}
|
|
487
474
|
}
|
|
488
475
|
}
|
|
489
476
|
},
|
|
490
|
-
|
|
491
477
|
shouldUpdate: (oldElement, newElement, isChild = false) => {
|
|
492
478
|
if (oldElement.nodeType !== newElement.nodeType) {
|
|
493
479
|
return oldElement.innerHTML !== newElement.innerHTML ? { type: "innerHTML" } : true;
|
|
@@ -504,7 +490,7 @@ export class Component {
|
|
|
504
490
|
return true;
|
|
505
491
|
}
|
|
506
492
|
if (newElement.attributes) {
|
|
507
|
-
for (let i = 0;
|
|
493
|
+
for (let i = 0;i < newElement.attributes.length; i++) {
|
|
508
494
|
let attr = newElement.attributes[i];
|
|
509
495
|
if (oldElement.getAttribute(attr.name) !== attr.value) {
|
|
510
496
|
return { type: "attribute", name: attr.name, value: attr.value };
|