Only update inputs when the value changed

Fixes #1699
pull/1703/head
Josh Duff 6 years ago
parent 6327647949
commit 211e0383cf

@ -66,7 +66,7 @@ export default class Binding extends Node {
dimensions.test(this.name) dimensions.test(this.name)
); );
let updateCondition: string; let updateConditions: string[] = [];
const { name } = getObject(this.value.node); const { name } = getObject(this.value.node);
const { snippet } = this.value; const { snippet } = this.value;
@ -108,7 +108,7 @@ export default class Binding extends Node {
} }
if (this.name === 'currentTime' || this.name === 'volume') { if (this.name === 'currentTime' || this.name === 'volume') {
updateCondition = `!isNaN(${snippet})`; updateConditions.push(`!isNaN(${snippet})`);
if (this.name === 'currentTime') initialUpdate = null; if (this.name === 'currentTime') initialUpdate = null;
} }
@ -118,7 +118,7 @@ export default class Binding extends Node {
const last = block.getUniqueName(`${node.var}_is_paused`); const last = block.getUniqueName(`${node.var}_is_paused`);
block.addVariable(last, 'true'); block.addVariable(last, 'true');
updateCondition = `${last} !== (${last} = ${snippet})`; updateConditions.push(`${last} !== (${last} = ${snippet})`);
updateDom = `${node.var}[${last} ? "pause" : "play"]();`; updateDom = `${node.var}[${last} ? "pause" : "play"]();`;
initialUpdate = null; initialUpdate = null;
} }
@ -129,6 +129,16 @@ export default class Binding extends Node {
updateDom = null; updateDom = null;
} }
const dependencyArray = [...this.value.dependencies]
if (dependencyArray.length === 1) {
updateConditions.push(`changed.${dependencyArray[0]}`)
} else if (dependencyArray.length > 1) {
updateConditions.push(
`(${dependencyArray.map(prop => `changed.${prop}`).join(' || ')})`
)
}
return { return {
name: this.name, name: this.name,
object: name, object: name,
@ -136,7 +146,7 @@ export default class Binding extends Node {
updateDom, updateDom,
initialUpdate, initialUpdate,
needsLock: !isReadOnly && needsLock, needsLock: !isReadOnly && needsLock,
updateCondition, updateCondition: updateConditions.length ? updateConditions.join(' && ') : undefined,
isReadOnlyMediaAttribute: this.isReadOnlyMediaAttribute() isReadOnlyMediaAttribute: this.isReadOnlyMediaAttribute()
}; };
} }

@ -188,7 +188,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
if (!input_updating) input.files = ctx.files; if (!input_updating && changed.files) input.files = ctx.files;
}, },
d(detach) { d(detach) {

@ -25,7 +25,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
if (!input_updating) input.files = ctx.files; if (!input_updating && changed.files) input.files = ctx.files;
}, },
d(detach) { d(detach) {

@ -190,7 +190,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
input.value = ctx.value; if (changed.value) input.value = ctx.value;
}, },
d(detach) { d(detach) {

@ -23,7 +23,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
input.value = ctx.value; if (changed.value) input.value = ctx.value;
}, },
d(detach) { d(detach) {

@ -185,7 +185,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
input.checked = ctx.foo; if (changed.foo) input.checked = ctx.foo;
}, },
d(detach) { d(detach) {

@ -22,7 +22,7 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
input.checked = ctx.foo; if (changed.foo) input.checked = ctx.foo;
}, },
d(detach) { d(detach) {

@ -226,9 +226,9 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
if (!audio_updating && !isNaN(ctx.currentTime )) audio.currentTime = ctx.currentTime ; if (!audio_updating && !isNaN(ctx.currentTime ) && changed.currentTime) audio.currentTime = ctx.currentTime ;
if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused )) audio[audio_is_paused ? "pause" : "play"](); if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused ) && changed.paused) audio[audio_is_paused ? "pause" : "play"]();
if (!audio_updating && !isNaN(ctx.volume)) audio.volume = ctx.volume; if (!audio_updating && !isNaN(ctx.volume) && changed.volume) audio.volume = ctx.volume;
}, },
d(detach) { d(detach) {

@ -59,9 +59,9 @@ function create_main_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
if (!audio_updating && !isNaN(ctx.currentTime )) audio.currentTime = ctx.currentTime ; if (!audio_updating && !isNaN(ctx.currentTime ) && changed.currentTime) audio.currentTime = ctx.currentTime ;
if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused )) audio[audio_is_paused ? "pause" : "play"](); if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused ) && changed.paused) audio[audio_is_paused ? "pause" : "play"]();
if (!audio_updating && !isNaN(ctx.volume)) audio.volume = ctx.volume; if (!audio_updating && !isNaN(ctx.volume) && changed.volume) audio.volume = ctx.volume;
}, },
d(detach) { d(detach) {

Loading…
Cancel
Save