From 2e425df7cdee6f0057664dbfd507a125a59f31a8 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Thu, 16 Oct 2014 19:55:15 -0700 Subject: [PATCH] In Todos, don't re-render all items when unnecessary Prior to this commit, any time the 'incompleteCount' field of a list changes (due to a new task being added or a task marked complete), we'd re-render the entire list of tasks. --- .../todos/client/templates/lists-show.html | 22 +++++++++++-------- examples/todos/client/templates/lists-show.js | 6 ++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/todos/client/templates/lists-show.html b/examples/todos/client/templates/lists-show.html index 50e0ee0ce6..7b5efcd25e 100644 --- a/examples/todos/client/templates/lists-show.html +++ b/examples/todos/client/templates/lists-show.html @@ -53,14 +53,18 @@
{{#if todosReady}} - {{#each todos}} - {{> todosItem}} - {{else}} -
-
No tasks here
-
Add new tasks using the field above
-
- {{/each}} + {{#with _id}} {{! Establish new data context with only the '_id' + field. This way, when the 'incompleteCount' field + changes, we don't re-render the list contents }} + {{#each todos this}} + {{> todosItem}} + {{else}} +
+
No tasks here
+
Add new tasks using the field above
+
+ {{/each}} + {{/with}} {{else}}
Loading tasks...
@@ -68,4 +72,4 @@ {{/if}}
- \ No newline at end of file + diff --git a/examples/todos/client/templates/lists-show.js b/examples/todos/client/templates/lists-show.js index 483709d350..65eeb55fe2 100644 --- a/examples/todos/client/templates/lists-show.js +++ b/examples/todos/client/templates/lists-show.js @@ -26,8 +26,8 @@ Template.listsShow.helpers({ return Router.current().todosHandle.ready(); }, - todos: function() { - return Todos.find({listId: this._id}, {sort: {createdAt : -1}}); + todos: function(listId) { + return Todos.find({listId: listId}, {sort: {createdAt : -1}}); } }); @@ -157,4 +157,4 @@ Template.listsShow.events({ Lists.update(this._id, {$inc: {incompleteCount: 1}}); $input.val(''); } -}); \ No newline at end of file +});