From 142af3a38fb4e7553699c62ca4249f8002ffd0f8 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Mon, 9 Jun 2014 14:29:29 -0700 Subject: [PATCH] Blaze.Isolate does basic deduping --- packages/blaze/render.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/blaze/render.js b/packages/blaze/render.js index 8b652b5ac3..a0b4874cad 100644 --- a/packages/blaze/render.js +++ b/packages/blaze/render.js @@ -6,6 +6,18 @@ var _onstopForRender = function () { Blaze.RenderController = Blaze.Controller.extend(); +var contentEquals = function (a, b) { + if (a instanceof HTML.Raw) { + return (b instanceof HTML.Raw) && (a.value === b.value); + } else if (a == null) { + return (b == null); + } else { + return (a === b) && + ((typeof a === 'number') || (typeof a === 'boolean') || + (typeof a === 'string')); + } +}; + // Takes a function that returns HTMLjs and returns a DOMRange. // The function will be reactively re-run. The resulting DOMRange // may be attached to the DOM using `.attach(parentElement, [nextNode])`. @@ -15,10 +27,14 @@ Blaze.render = function (func) { if (! controller) controller = new Blaze.RenderController; - range.computation = Deps.autorun(function () { + var oldContent; + range.computation = Deps.autorun(function (c) { Blaze.withCurrentController(controller, function () { var content = func(); - range.setMembers(Blaze.toDOM(content)); + if (c.firstRun || ! contentEquals(oldContent, content)) { + oldContent = content; + range.setMembers(Blaze.toDOM(content)); + } }); }); Blaze._wrapAutorun(range.computation);