Skip to content

Commit

Permalink
Initialise media element's range bindings to an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
martinandert committed Sep 10, 2017
1 parent 687acf7 commit bfaab99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/generators/dom/visitors/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function getBindingValue(
}

if (isMediaElement && (attribute.name === 'buffered' || attribute.name === 'seekable' || attribute.name === 'played')) {
return `@timeRangesToArray(${state.parentNode}.${attribute.name})`
return `${state.parentNode}.${attribute.name} ? @timeRangesToArray(${state.parentNode}.${attribute.name}) : []`
}

// everything else
Expand Down
6 changes: 3 additions & 3 deletions test/js/samples/media-bindings/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,19 @@ function create_main_fragment(state, component) {

function audio_progress_loadedmetadata_handler() {
audio_updating = true;
component.set({ buffered: timeRangesToArray(audio.buffered) });
component.set({ buffered: audio.buffered ? timeRangesToArray(audio.buffered) : [] });
audio_updating = false;
}

function audio_loadedmetadata_handler() {
audio_updating = true;
component.set({ seekable: timeRangesToArray(audio.seekable) });
component.set({ seekable: audio.seekable ? timeRangesToArray(audio.seekable) : [] });
audio_updating = false;
}

function audio_timeupdate_handler() {
audio_updating = true;
component.set({ played: timeRangesToArray(audio.played) });
component.set({ played: audio.played ? timeRangesToArray(audio.played) : [] });
audio_updating = false;
}

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/media-bindings/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ function create_main_fragment(state, component) {

function audio_progress_loadedmetadata_handler() {
audio_updating = true;
component.set({ buffered: timeRangesToArray(audio.buffered) });
component.set({ buffered: audio.buffered ? timeRangesToArray(audio.buffered) : [] });
audio_updating = false;
}

function audio_loadedmetadata_handler() {
audio_updating = true;
component.set({ seekable: timeRangesToArray(audio.seekable) });
component.set({ seekable: audio.seekable ? timeRangesToArray(audio.seekable) : [] });
audio_updating = false;
}

function audio_timeupdate_handler() {
audio_updating = true;
component.set({ played: timeRangesToArray(audio.played) });
component.set({ played: audio.played ? timeRangesToArray(audio.played) : [] });
audio_updating = false;
}

Expand Down Expand Up @@ -138,4 +138,4 @@ function SvelteComponent(options) {

assign(SvelteComponent.prototype, proto );

export default SvelteComponent;
export default SvelteComponent;

0 comments on commit bfaab99

Please sign in to comment.