on master help sign in
Get rid of memory leak caused by creating tons of canvases.
commita764f68646c5097bb4955856c2e6f2e1bf1e0b8c authorevancz <info@elm-lang.org> dateThu 18 Apr 2013, 22:25 (14 years ago) parent95726b7
1 file changed+8−1
runtime/Render/Collage.js+8−1
runtime/Render/Collage.js+8−1
@@ -189,7 +189,14 @@ function render(model) {
189189}
190190
191191function update(node, oldModel, newModel) {
192− node.parentNode.replaceChild(render(newModel), node);
192+ if (!node.getContext) {
193+ return node.parentNode.replaceChild(render(newModel), node);
194+ }
195+ var ctx = node.getContext('2d');
196+ var w = newModel.w, h = newModel.h;
197+ ctx.clearRect(-w/2, -h/2, w, h);
198+ function redo() { renderForms( this, ctx, newModel.forms ); }
199+ renderForms( redo, ctx, newModel.forms );
193200}
194201
195202return { render:render, update:update };