on master help sign in
Correctly update model, accounting for possibly dropped frames

Thanks to @johnpmayer for discovering this issue! Since draw is async, it was possible to update the model without updating the underlying DOM stuff. This could cause issues on its own, but if you need to pass info from model to model, that is also lost when this happens.

commit4b1474dcdc25e99d6d05c889a37e32b5eb58ec2c authorEvan Czaplicki <info@elm-lang.org> dateMon 20 Jan 2014, 19:55 (13 years ago) parent6556b1b
1 file changed+5−4
runtime/Init.js+5−4
runtime/Init.js+5−4
@@ -220,14 +220,15 @@ function initGraphics(elm, Module) {
220220 elm.node.appendChild(Render.render(currentScene));
221221
222222 // set up updates so that the DOM is adjusted as necessary.
223− function domUpdate(newScene, currentScene) {
223+ var savedScene = currentScene;
224+ function domUpdate(newScene) {
224225 ElmRuntime.draw(function(_) {
225− Render.update(elm.node.firstChild, currentScene, newScene);
226+ Render.update(elm.node.firstChild, savedScene, newScene);
226227 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
228+ savedScene = newScene;
227229 });
228− return newScene;
229230 }
230− var renderer = A3(Signal.foldp, F2(domUpdate), currentScene, signalGraph);
231+ var renderer = A2(Signal.lift, domUpdate, signalGraph);
231232
232233 // must check for resize after 'renderer' is created so
233234 // that changes show up.