Merge pull request #2414 from sveltejs/gh-2395

deconflict `value` argument in component bindings
pull/2416/head
Rich Harris 5 years ago committed by GitHub
commit 08955da04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -327,13 +327,14 @@ export default class InlineComponentWrapper extends Wrapper {
contextual_dependencies.push(object, property); contextual_dependencies.push(object, property);
} }
const args = ['value']; const value = block.get_unique_name('value');
const args = [value];
if (contextual_dependencies.length > 0) { if (contextual_dependencies.length > 0) {
args.push(`{ ${contextual_dependencies.join(', ')} }`); args.push(`{ ${contextual_dependencies.join(', ')} }`);
block.builders.init.add_block(deindent` block.builders.init.add_block(deindent`
function ${name}(value) { function ${name}(${value}) {
if (ctx.${name}.call(null, value, ctx)) { if (ctx.${name}.call(null, ${value}, ctx)) {
${updating} = true; ${updating} = true;
} }
} }
@ -342,8 +343,8 @@ export default class InlineComponentWrapper extends Wrapper {
block.maintain_context = true; // TODO put this somewhere more logical block.maintain_context = true; // TODO put this somewhere more logical
} else { } else {
block.builders.init.add_block(deindent` block.builders.init.add_block(deindent`
function ${name}(value) { function ${name}(${value}) {
if (ctx.${name}.call(null, value)) { if (ctx.${name}.call(null, ${value})) {
${updating} = true; ${updating} = true;
} }
} }
@ -352,7 +353,7 @@ export default class InlineComponentWrapper extends Wrapper {
const body = deindent` const body = deindent`
function ${name}(${args.join(', ')}) { function ${name}(${args.join(', ')}) {
${lhs} = value; ${lhs} = ${value};
return ${component.invalidate(dependencies[0])} return ${component.invalidate(dependencies[0])}
} }
`; `;

@ -0,0 +1,3 @@
<script>
export let value = 'foo';
</script>

@ -0,0 +1,6 @@
export default {
html: `
<p>Reactive: foo</p>
<p>Value: foo</p>
`
};

@ -0,0 +1,9 @@
<script>
import Widget from './Widget.svelte';
let value;
$: reactive = value;
</script>
<Widget bind:value/>
<p>Reactive: {reactive}</p>
<p>Value: {value}</p>
Loading…
Cancel
Save