Skip to content

Commit defe9cc

Browse files
committed
Make the draw queue per app instance
1 parent 19ff487 commit defe9cc

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/Elm/Kernel/Browser.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,16 @@ var _Browser_requestAnimationFrame_raw =
139139
? requestAnimationFrame
140140
: function(callback) { return setTimeout(callback, 1000 / 60); };
141141

142-
// Whether `draw` is currently running. `draw` can cause side effects:
143-
// If the user renders a custom element, they can dispatch an event in
144-
// its `connectedCallback`, which happens synchronously. That causes
145-
// `update` to run while we’re in the middle of drawing, which then
146-
// causes another call to the returned function below. We can’t start
147-
// another draw before the first one is finished.
148-
// Another thing you can do in `connectedCallback`, is to initialize
149-
// another Elm app. Even different app instances can conflict with each other,
150-
// since they all use the same `_VirtualDom_renderCount` variable.
151-
var _Browser_drawing = false;
152-
var _Browser_drawSync_queue = [];
153-
154142
function _Browser_makeAnimator(model, draw)
155143
{
144+
// Whether `draw` is currently running. `draw` can cause side effects:
145+
// If the user renders a custom element, they can dispatch an event in
146+
// its `connectedCallback`, which happens synchronously. That causes
147+
// `update` to run while we’re in the middle of drawing, which then
148+
// causes another call to the returned function below. We can’t start
149+
// another draw while before the first one is finished.
150+
var drawing = false;
151+
156152
// Whether we have already requested an animation frame for drawing.
157153
var pendingFrame = false;
158154

@@ -162,26 +158,21 @@ function _Browser_makeAnimator(model, draw)
162158
function drawHelp()
163159
{
164160
// If we’re already drawing, wait until that draw is done.
165-
if (_Browser_drawing)
161+
if (drawing)
166162
{
167-
if (!pendingSync)
168-
{
169-
pendingSync = true;
170-
_Browser_drawSync_queue.push(drawHelp);
171-
}
163+
pendingSync = true;
172164
return;
173165
}
174166

175167
pendingFrame = false;
176168
pendingSync = false;
177-
_Browser_drawing = true;
169+
drawing = true;
178170
draw(model);
179-
_Browser_drawing = false;
171+
drawing = false;
180172

181-
while (_Browser_drawSync_queue.length > 0)
173+
if (pendingSync)
182174
{
183-
var callback = _Browser_drawSync_queue.shift();
184-
callback();
175+
drawHelp();
185176
}
186177
}
187178

0 commit comments

Comments
 (0)