From 8ca9541391c972ad65974cdf2a05cd81c460a939 Mon Sep 17 00:00:00 2001 From: pushkine Date: Sat, 16 Jan 2021 15:00:58 +0100 Subject: [PATCH 1/5] init --- .../render_dom/wrappers/InlineComponent/index.ts | 6 ++++-- .../Component.svelte | 5 +++++ .../_config.js | 5 +++++ .../main.svelte | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index be3d6d146d97..515cdc084152 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -378,8 +378,10 @@ export default class InlineComponentWrapper extends Wrapper { const body = b` function ${id}(${params}) { - ${lhs} = #value; - ${renderer.invalidate(dependencies[0])}; + if ($$self.$$.not_equal(${lhs}, #value)) { + ${lhs} = #value; + ${renderer.invalidate(dependencies[0])}; + } } `; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte new file mode 100644 index 000000000000..35bea4786d5c --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte @@ -0,0 +1,5 @@ + + +{value} diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js new file mode 100644 index 000000000000..ae7b55e100e1 --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js @@ -0,0 +1,5 @@ +export default { + async test({ assert, component }) { + assert.equal(component.object_updates, 1); + }, +}; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte new file mode 100644 index 000000000000..768f8c22a9aa --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte @@ -0,0 +1,10 @@ + + + From 2a72bfa883599108c253f338f768d2c557856410 Mon Sep 17 00:00:00 2001 From: pushkine Date: Sat, 16 Jan 2021 18:46:44 +0100 Subject: [PATCH 2/5] better --- .../wrappers/InlineComponent/index.ts | 36 ++++++++++--------- .../Component.svelte | 3 +- .../_config.js | 2 +- .../main.svelte | 9 +++-- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 515cdc084152..cf78127510fa 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -347,8 +347,8 @@ export default class InlineComponentWrapper extends Wrapper { } const params = [x`#value`]; + const args = [x`#value`]; if (contextual_dependencies.length > 0) { - const args = []; contextual_dependencies.forEach(name => { params.push({ @@ -361,27 +361,29 @@ export default class InlineComponentWrapper extends Wrapper { }); - block.chunks.init.push(b` - function ${id}(#value) { - ${callee}.call(null, #value, ${args}); - } - `); - block.maintain_context = true; // TODO put this somewhere more logical - } else { - block.chunks.init.push(b` - function ${id}(#value) { - ${callee}.call(null, #value); - } - `); + } + + block.chunks.init.push(b` + function ${id}(#value) { + ${callee}(${args}); + } + `); + + let invalidate_binding = b` + ${lhs} = #value; + ${renderer.invalidate(dependencies[0])}; + ` + if (binding.expression.node.type === "MemberExpression") { + invalidate_binding = b` + if ($$self.$$.not_equal(${lhs}, #value)) { + ${invalidate_binding} + }` } const body = b` function ${id}(${params}) { - if ($$self.$$.not_equal(${lhs}, #value)) { - ${lhs} = #value; - ${renderer.invalidate(dependencies[0])}; - } + ${invalidate_binding} } `; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte index 35bea4786d5c..f180f10cd848 100644 --- a/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte @@ -1,5 +1,6 @@ -{value} +{value}{value2} diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js index ae7b55e100e1..f46d5d7df4ad 100644 --- a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js @@ -1,5 +1,5 @@ export default { async test({ assert, component }) { - assert.equal(component.object_updates, 1); + assert.equal(component.object_updates, component.primitive_updates); }, }; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte index 768f8c22a9aa..bd4e4e0333f6 100644 --- a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte @@ -1,10 +1,13 @@ - + From 05c0f74ff3626416a23c564f136dd8ff24d2fc4a Mon Sep 17 00:00:00 2001 From: pushkine Date: Sat, 16 Jan 2021 20:08:23 +0100 Subject: [PATCH 3/5] lint --- .../compile/render_dom/wrappers/InlineComponent/index.ts | 8 ++++---- .../_config.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index cf78127510fa..57a727cb9ea7 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -363,7 +363,7 @@ export default class InlineComponentWrapper extends Wrapper { block.maintain_context = true; // TODO put this somewhere more logical } - + block.chunks.init.push(b` function ${id}(#value) { ${callee}(${args}); @@ -373,12 +373,12 @@ export default class InlineComponentWrapper extends Wrapper { let invalidate_binding = b` ${lhs} = #value; ${renderer.invalidate(dependencies[0])}; - ` - if (binding.expression.node.type === "MemberExpression") { + `; + if (binding.expression.node.type === 'MemberExpression') { invalidate_binding = b` if ($$self.$$.not_equal(${lhs}, #value)) { ${invalidate_binding} - }` + }`; } const body = b` diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js index f46d5d7df4ad..7027c1a4e4f8 100644 --- a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js @@ -1,5 +1,5 @@ export default { async test({ assert, component }) { assert.equal(component.object_updates, component.primitive_updates); - }, + } }; From 149dfc3059b857936fdb783c4e5aa63a7905590b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 8 Feb 2021 14:07:42 -0500 Subject: [PATCH 4/5] lint --- .../main.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte index bd4e4e0333f6..9d52ed675f3b 100644 --- a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte @@ -1,11 +1,11 @@ From ddaece19ad4f1c48b99c0e66013682aa093276a5 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 8 Feb 2021 14:13:49 -0500 Subject: [PATCH 5/5] adjust indentation --- .../compile/render_dom/wrappers/InlineComponent/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 57a727cb9ea7..835e0b52ce88 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -376,9 +376,10 @@ export default class InlineComponentWrapper extends Wrapper { `; if (binding.expression.node.type === 'MemberExpression') { invalidate_binding = b` - if ($$self.$$.not_equal(${lhs}, #value)) { - ${invalidate_binding} - }`; + if ($$self.$$.not_equal(${lhs}, #value)) { + ${invalidate_binding} + } + `; } const body = b`