muu

DEPRECATED lightweight JS framework
git clone https://git.ce9e.org/muu.git

commit
890cf4261a746ff7984dca0dd1681eb190aa1779
parent
8432de746b8b2d5c41c3491118a11759f30b77b3
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-09-10 10:32
fix bug in updateDOM

Diffstat

M src/muu-update-dom.js 4 +++-
M test/test-update-dom.js 6 ++++++

2 files changed, 9 insertions, 1 deletions


diff --git a/src/muu-update-dom.js b/src/muu-update-dom.js

@@ -50,6 +50,7 @@ define('muu-update-dom', ['muu-js-helpers'], function(_) {
   50    50     var updateDOM = function(target, source) {
   51    51         var nt = target.childNodes.length;
   52    52         var ns = source.childNodes.length;
   -1    53         var offset = 0;
   53    54 
   54    55         for (var i = ns; i < nt; i++) {
   55    56             target.removeChild(target.childNodes[ns]);
@@ -59,7 +60,7 @@ define('muu-update-dom', ['muu-js-helpers'], function(_) {
   59    60         }
   60    61         for (i = 0; i < nt && i < ns; i++) {
   61    62             var tchild = target.childNodes[i];
   62    -1             var schild = source.childNodes[i];
   -1    63             var schild = source.childNodes[i - offset];
   63    64 
   64    65             if (tchild.nodeType === schild.nodeType && tchild.nodeName === schild.nodeName && tchild.type === schild.type) {
   65    66                 if (tchild.nodeType === 1) {
@@ -78,6 +79,7 @@ define('muu-update-dom', ['muu-js-helpers'], function(_) {
   78    79                 }
   79    80             } else {
   80    81                 tchild.parentNode.replaceChild(schild, tchild);
   -1    82                 offset += 1;
   81    83             }
   82    84         }
   83    85     };

diff --git a/test/test-update-dom.js b/test/test-update-dom.js

@@ -53,6 +53,12 @@ define(['muu-update-dom'], function(updateDOM) {
   53    53             updateDOM(target, source);
   54    54             expect(n(target.innerHTML)).to.equal('<div>1</div> <div>2</div>');
   55    55         });
   -1    56         it('can replace more than one element in the same parent', function() {
   -1    57             source.innerHTML = '<div>1</div> <div>2</div>';
   -1    58             target.innerHTML = '<span>1</span> <span>2</span>';
   -1    59             updateDOM(target, source);
   -1    60             expect(n(target.innerHTML)).to.equal('<div>1</div> <div>2</div>');
   -1    61         });
   56    62         it('can replace and remove elements in the same parent', function() {
   57    63             source.innerHTML = '<div>1</div>';
   58    64             target.innerHTML = '<span>1</span> <div>2</div>';