From 687acf77330ba3a0132c1b9df78fdf9abb6646f1 Mon Sep 17 00:00:00 2001 From: martinandert Date: Sun, 10 Sep 2017 23:52:30 +0200 Subject: [PATCH 1/2] Add parenthesis around or'd expression --- src/generators/dom/visitors/Element/Binding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/dom/visitors/Element/Binding.ts b/src/generators/dom/visitors/Element/Binding.ts index 549cb05ecb17..edc3767c0e77 100644 --- a/src/generators/dom/visitors/Element/Binding.ts +++ b/src/generators/dom/visitors/Element/Binding.ts @@ -266,7 +266,7 @@ function getBindingValue( return `@toNumber(${state.parentNode}.${attribute.name})`; } - if (isMediaElement && attribute.name === 'buffered' || attribute.name === 'seekable' || attribute.name === 'played') { + if (isMediaElement && (attribute.name === 'buffered' || attribute.name === 'seekable' || attribute.name === 'played')) { return `@timeRangesToArray(${state.parentNode}.${attribute.name})` } From bfaab9967a2294674f0a2f3b81dea67fff6739d8 Mon Sep 17 00:00:00 2001 From: martinandert Date: Mon, 11 Sep 2017 00:55:00 +0200 Subject: [PATCH 2/2] Initialise media element's range bindings to an empty array --- src/generators/dom/visitors/Element/Binding.ts | 2 +- test/js/samples/media-bindings/expected-bundle.js | 6 +++--- test/js/samples/media-bindings/expected.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/generators/dom/visitors/Element/Binding.ts b/src/generators/dom/visitors/Element/Binding.ts index edc3767c0e77..ad22eaa27bc8 100644 --- a/src/generators/dom/visitors/Element/Binding.ts +++ b/src/generators/dom/visitors/Element/Binding.ts @@ -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 diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 631999398cff..a0326ae7319a 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -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; } diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 52a6a00a5350..7e7817ec9415 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -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; } @@ -138,4 +138,4 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto ); -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent;