From 63ae77112c8bfa175c5294af99faba12c628a07c Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 7 Sep 2019 17:36:10 -0400 Subject: [PATCH 1/3] robustify bind:currentTime - fixes #3524 --- src/compiler/compile/render_dom/wrappers/Element/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 9e267b9ad06a..d091b07d51a4 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -472,8 +472,10 @@ export default class ElementWrapper extends Wrapper { function ${handler}() { ${animation_frame && deindent` @_cancelAnimationFrame(${animation_frame}); - if (!${this.var}.paused) ${animation_frame} = @raf(${handler});`} - ${needs_lock && `${lock} = true;`} + if (!${this.var}.paused) { + ${animation_frame} = @raf(${handler});`} + ${needs_lock && `${lock} = true;`} + } ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''}); } `); From 4ad36406bc576824287c509da89741d65b35c707 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 7 Sep 2019 18:04:16 -0400 Subject: [PATCH 2/3] doh --- .../render_dom/wrappers/Element/index.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index d091b07d51a4..1ae315165aad 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -468,17 +468,25 @@ export default class ElementWrapper extends Wrapper { // TODO dry this out — similar code for event handlers and component bindings if (has_local_function) { // need to create a block-local function that calls an instance-level function - block.builders.init.add_block(deindent` - function ${handler}() { - ${animation_frame && deindent` - @_cancelAnimationFrame(${animation_frame}); - if (!${this.var}.paused) { - ${animation_frame} = @raf(${handler});`} + if (animation_frame) { + block.builders.init.add_block(deindent` + function ${handler}() { + @_cancelAnimationFrame(${animation_frame}); + if (!${this.var}.paused) { + ${animation_frame} = @raf(${handler}); + ${needs_lock && `${lock} = true;`} + } + ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''}); + } + `); + } else { + block.builders.init.add_block(deindent` + function ${handler}() { ${needs_lock && `${lock} = true;`} + ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''}); } - ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''}); - } - `); + `); + } callee = handler; } else { From 8d4a95c4c0c4d5f80a908cb207dd2579aba60284 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 7 Sep 2019 18:04:25 -0400 Subject: [PATCH 3/3] update test --- test/js/samples/media-bindings/expected.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index f45f9ce8dbfb..b67bc31ed352 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -19,8 +19,10 @@ function create_fragment(ctx) { function audio_timeupdate_handler() { cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = raf(audio_timeupdate_handler); - audio_updating = true; + if (!audio.paused) { + audio_animationframe = raf(audio_timeupdate_handler); + audio_updating = true; + } ctx.audio_timeupdate_handler.call(audio); }