on master help sign in
Fix #673, fix rendering with multiple embedded elements
453e9caEvan Czaplicki
runtime/Init.js+2−1
@@ -221,8 +221,9 @@ function initGraphics(elm, Module) {
221
221
222 // set up updates so that the DOM is adjusted as necessary.
222 // set up updates so that the DOM is adjusted as necessary.
223 var savedScene = currentScene;
223 var savedScene = currentScene;
224+ var previousDrawId = 0;
224 function domUpdate(newScene) {
225 function domUpdate(newScene) {
225− ElmRuntime.draw(function(_) {
226+ previousDrawId = ElmRuntime.draw(previousDrawId, function(_) {
226 Render.update(elm.node.firstChild, savedScene, newScene);
227 Render.update(elm.node.firstChild, savedScene, newScene);
227 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
228 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
228 savedScene = newScene;
229 savedScene = newScene;
runtime/Utils.js+14−6
@@ -32,7 +32,13 @@ ElmRuntime.filterDeadInputs = function(inputs) {
32 return temp;
32 return temp;
33};
33};
34
34
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+//
36var vendors = ['ms', 'moz', 'webkit', 'o'];
42var vendors = ['ms', 'moz', 'webkit', 'o'];
37var win = typeof window !== 'undefined' ? window : {};
43var win = typeof window !== 'undefined' ? window : {};
38for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) {
44for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) {
@@ -42,13 +48,15 @@ for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) {
42}
48}
43
49
44if (win.requestAnimationFrame && win.cancelAnimationFrame) {
50if (win.requestAnimationFrame && win.cancelAnimationFrame) {
45− var previous = 0;
46− ElmRuntime.draw = function(callback) {
51+ ElmRuntime.draw = function(previousRequestID, callback) {
47− win.cancelAnimationFrame(previous);
52+ win.cancelAnimationFrame(previousRequestID);
48− previous = win.requestAnimationFrame(callback);
53+ return win.requestAnimationFrame(callback);
49 };
54 };
50} else {
55} else {
51− ElmRuntime.draw = function(callback) { callback(); };
56+ ElmRuntime.draw = function(previousRequestID, callback) {
57+ callback();
58+ return previousRequestID;
59+ };
52}
60}
53
61
54}());
62}());