on master help sign in
Fix #673, fix rendering with multiple embedded elements
commit453e9ca0b59e9cbbfc9e2616ed3b6052866c091a authorEvan Czaplicki <info@elm-lang.org> dateThu 24 Jul 2014, 16:20 (12 years ago) parentdcf6581
2 files changed+16−7
runtime/Init.js+2−1 runtime/Utils.js+14−6
runtime/Init.js+2−1
@@ -221,8 +221,9 @@ function initGraphics(elm, Module) {
221221
222222 // set up updates so that the DOM is adjusted as necessary.
223223 var savedScene = currentScene;
224+ var previousDrawId = 0;
224225 function domUpdate(newScene) {
225− ElmRuntime.draw(function(_) {
226+ previousDrawId = ElmRuntime.draw(previousDrawId, function(_) {
226227 Render.update(elm.node.firstChild, savedScene, newScene);
227228 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
228229 savedScene = newScene;
runtime/Utils.js+14−6
@@ -32,7 +32,13 @@ ElmRuntime.filterDeadInputs = function(inputs) {
3232 return temp;
3333};
3434
35−// define the draw function
35+// define function for drawing efficiently
36+//
37+// draw : RequestID -> (() -> ()) -> RequestID
38+//
39+// Takes a "RequestID" allowing you to cancel old requests if possible.
40+// Returns a "RequestID" so you can refer to past requests.
41+//
3642var vendors = ['ms', 'moz', 'webkit', 'o'];
3743var win = typeof window !== 'undefined' ? window : {};
3844for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) {
@@ -42,13 +48,15 @@ for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) {
4248}
4349
4450if (win.requestAnimationFrame && win.cancelAnimationFrame) {
45− var previous = 0;
46− ElmRuntime.draw = function(callback) {
47− win.cancelAnimationFrame(previous);
48− previous = win.requestAnimationFrame(callback);
51+ ElmRuntime.draw = function(previousRequestID, callback) {
52+ win.cancelAnimationFrame(previousRequestID);
53+ return win.requestAnimationFrame(callback);
4954 };
5055} else {
51− ElmRuntime.draw = function(callback) { callback(); };
56+ ElmRuntime.draw = function(previousRequestID, callback) {
57+ callback();
58+ return previousRequestID;
59+ };
5260}
5361
5462}());