Skip to content

Commit 52999d7

Browse files
committed
v.5.0.0 contd
* optimize collection replace items a bit * update benchmarks
1 parent 6f60c92 commit 52999d7

13 files changed

Lines changed: 61 additions & 27 deletions

File tree

build/modelview.bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/modelview.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* ModelView.js
44
* @version: 5.0.0
5-
* @built on 2022-03-25 10:21:59
5+
* @built on 2022-03-25 15:11:46
66
*
77
* A simple, light-weight, versatile and fast isomorphic MVVM JavaScript framework (Browser and Server)
88
* https://github.com/foo123/modelview.js
@@ -11,7 +11,7 @@
1111
*
1212
* ModelView.js
1313
* @version: 5.0.0
14-
* @built on 2022-03-25 10:21:59
14+
* @built on 2022-03-25 15:11:46
1515
*
1616
* A simple, light-weight, versatile and fast isomorphic MVVM JavaScript framework (Browser and Server)
1717
* https://github.com/foo123/modelview.js
@@ -1541,10 +1541,10 @@ function htmlNode(view, nodeType, id, type, atts, children, value2, modified)
15411541
{
15421542
if (val.id()) view.$reset[val.id()] = val;
15431543
n.changed = true;
1544-
n.uNodes = (function(t) {
1544+
n.uNodes = (function(val) {
15451545
return function(view, r, v) {
1546-
if (r.nodeValue !== t)
1547-
r.nodeValue = t;
1546+
if (r.nodeValue !== val)
1547+
r.nodeValue = val;
15481548
};
15491549
})(v);
15501550
}
@@ -1556,10 +1556,10 @@ function htmlNode(view, nodeType, id, type, atts, children, value2, modified)
15561556
if (!node.modified) node.modified = {atts: [], nodes: []};
15571557
new_mod = insMod(node.modified.nodes, index, index, new_mod);
15581558
n.changed = true;
1559-
n.uNodes = (function(t) {
1559+
n.uNodes = (function(val) {
15601560
return function(view, r, v) {
1561-
if (r.nodeValue !== t)
1562-
r.nodeValue = t;
1561+
if (r.nodeValue !== val)
1562+
r.nodeValue = val;
15631563
};
15641564
})(v);
15651565
}
@@ -2256,7 +2256,7 @@ function morphCollection(view, r, v, start, end, end2, startv, count)
22562256
return count; // break from diff loop completely, this should be only diff
22572257
break;
22582258
case 'replace':
2259-
len = collection.items().length*m;
2259+
/*len = collection.items().length*m;
22602260
items = collection.mapped();
22612261
frag = {nodeType:'',childNodes:mergeChildNodes(items)};
22622262
x = r.childNodes[start];
@@ -2277,7 +2277,12 @@ function morphCollection(view, r, v, start, end, end2, startv, count)
22772277
{
22782278
//delete excess nodes
22792279
delNodes(view, r, start+len, count);
2280-
}
2280+
}*/
2281+
// delete all and add new
2282+
len = collection.items().length*m;
2283+
delNodes(view, r, start, stdMath.min(len, len+count));
2284+
items = collection.mapped();
2285+
insNodes(view, r, {nodeType:'',childNodes:mergeChildNodes(items)}, 0, len, r.childNodes[start]);
22812286
count = 0;
22822287
return count; // break from diff loop completely, this should be only diff
22832288
break;
@@ -3134,7 +3139,7 @@ function morphCollectionSimple(view, list, key, collection, isDirty, model, only
31343139
}
31353140
return;
31363141
case 'replace':
3137-
count = items.length - list.map.length;
3142+
/*count = items.length - list.map.length;
31383143
// replace common nodes
31393144
n = parentNode.childNodes[startIndex + 1];
31403145
iterate(function(index) {
@@ -3165,7 +3170,19 @@ function morphCollectionSimple(view, list, key, collection, isDirty, model, only
31653170
// remove excess nodes
31663171
list.map.splice(items.length, -count);
31673172
delNodes(null, parentNode, startIndex+1+m*items.length, -m*count);
3168-
}
3173+
}*/
3174+
// delete all and add new
3175+
delNodes(null, parentNode, startIndex+1, m*list.map.length);
3176+
list.map = new Array(items.length);
3177+
frag = Fragment();
3178+
iterate(function(index) {
3179+
var node = clone(list);
3180+
list.map[index] = node.map;
3181+
morphSimple(view, list.map[index], model.getProxy(key+'.'+index, '.', items[index]), false);
3182+
frag.appendChild(node.dom);
3183+
}, 0, items.length-1);
3184+
if (end) parentNode.insertBefore(frag, end);
3185+
else parentNode.appendChild(frag);
31693186
return;
31703187
case 'reorder':
31713188
count = items.length;

build/modelview.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/mem.png

-87 Bytes
Loading

examples/mem2.png

-304 Bytes
Loading

examples/mem2s.png

-3.33 KB
Loading

examples/mems.png

742 Bytes
Loading

examples/perf.png

925 Bytes
Loading

examples/perf2.png

689 Bytes
Loading

examples/perf2s.png

-8.72 KB
Loading

0 commit comments

Comments
 (0)