Skip to content

Commit fd5125a

Browse files
author
pemrouz
committed
skip unnecessary todo-item renders
1 parent 9f4502c commit fd5125a

File tree

6 files changed

+243
-40
lines changed

6 files changed

+243
-40
lines changed

time-travel-todo/dist/app.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function todo(_ref) {
9696

9797
o('todo-footer', { items: items, filter: filter });
9898

99-
o('todo-item', visible, null, 'todo-footer').each(ripple.draw);
99+
o('todo-item', changed(visible), null, 'todo-footer');
100100

101101
function addItem() {
102102
if (window.event.which != 13 || !this.value) return;
@@ -108,6 +108,19 @@ function todo(_ref) {
108108

109109
this.value = '';
110110
}
111+
112+
function changed(items) {
113+
var _o$node = o.node();
114+
115+
var change = _o$node.change;
116+
var key;
117+
118+
return change.length !== 1 ? items : !change[0] ? items : change[0][0] !== 'items' ? items : !isFinite(key = change[0][1].key.split('.').shift()) ? items : items.map(function (_ref2) {
119+
var completed = _ref2.completed;
120+
var item = _ref2.item;
121+
return { completed: completed, item: item, key: key };
122+
});
123+
}
111124
}
112125
},{}],8:[function(require,module,exports){
113126
'use strict';
@@ -144,14 +157,16 @@ Object.defineProperty(exports, "__esModule", {
144157
});
145158
exports.default = item;
146159
function item(d, i) {
160+
if ('key' in d && d.key != --i) return;
161+
147162
var complete = function complete(el) {
148163
return function (d) {
149-
return update(i - 1 + '.completed', el.checked)(ripple('items'));
164+
return update(i + '.completed', el.checked)(ripple('items'));
150165
};
151166
},
152167
destroy = function destroy(el) {
153168
return function (d) {
154-
return remove(i - 1)(ripple('items'));
169+
return remove(i)(ripple('items'));
155170
};
156171
},
157172
o = once(this);

time-travel-todo/dist/resources/todo-app/todo-app.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function todo(_ref) {
1515

1616
o('todo-footer', { items: items, filter: filter });
1717

18-
o('todo-item', visible, null, 'todo-footer').each(ripple.draw);
18+
o('todo-item', changed(visible), null, 'todo-footer');
1919

2020
function addItem() {
2121
if (window.event.which != 13 || !this.value) return;
@@ -27,4 +27,17 @@ function todo(_ref) {
2727

2828
this.value = '';
2929
}
30+
31+
function changed(items) {
32+
var _o$node = o.node();
33+
34+
var change = _o$node.change;
35+
var key;
36+
37+
return change.length !== 1 ? items : !change[0] ? items : change[0][0] !== 'items' ? items : !isFinite(key = change[0][1].key.split('.').shift()) ? items : items.map(function (_ref2) {
38+
var completed = _ref2.completed;
39+
var item = _ref2.item;
40+
return { completed: completed, item: item, key: key };
41+
});
42+
}
3043
}

time-travel-todo/dist/resources/todo-item/todo-item.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = item;
77
function item(d, i) {
8+
if ('key' in d && d.key != --i) return;
9+
810
var complete = function complete(el) {
911
return function (d) {
10-
return update(i - 1 + '.completed', el.checked)(ripple('items'));
12+
return update(i + '.completed', el.checked)(ripple('items'));
1113
};
1214
},
1315
destroy = function destroy(el) {
1416
return function (d) {
15-
return remove(i - 1)(ripple('items'));
17+
return remove(i)(ripple('items'));
1618
};
1719
},
1820
o = once(this);

0 commit comments

Comments
 (0)