Skip to content

Commit

Permalink
Merge pull request #3530 from sveltejs/gh-3524
Browse files Browse the repository at this point in the history
robustify bind:currentTime
  • Loading branch information
Rich-Harris authored Sep 8, 2019
2 parents b6905f8 + 8d4a95c commit 1a9f6b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
28 changes: 19 additions & 9 deletions src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +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});`}
${needs_lock && `${lock} = true;`}
ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''});
}
`);
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' : ''});
}
`);
}

callee = handler;
} else {
Expand Down
6 changes: 4 additions & 2 deletions test/js/samples/media-bindings/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1a9f6b4

Please sign in to comment.