Skip to content

Fix binding this to a computed property #3079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 23, 2019
Merged

Conversation

btk5h
Copy link
Contributor

@btk5h btk5h commented Jun 23, 2019

This PR fixes #2333 by allowing flatten_reference to handle computed properties.

@btk5h
Copy link
Contributor Author

btk5h commented Jun 23, 2019

Oops, this doesn't work with things like array indices of each blocks.

@btk5h btk5h changed the title Fix binding this to a computed property [WIP] Fix binding this to a computed property Jun 23, 2019
@Conduitry
Copy link
Member

Thanks! I was just in the middle of writing up a comment saying that that's not working yet.

<script>
	import Foo from './Foo.svelte';
	let refs = [];
</script>

{#each { length: 5 } as _, i}
	<Foo bind:this={refs[i]}/>
{/each}

{JSON.stringify(refs)}

The foo_binding function looks like:

	function foo_binding($$component) {
		refs[i] = $$component;
		$$invalidate('refs', refs)
	}

I believe this function (and also where it's called) will need to be updated to use i as another argument. You can take a look at how this is implemented for DOM this bindings here.

@btk5h
Copy link
Contributor Author

btk5h commented Jun 23, 2019

Should be fixed now!

@btk5h btk5h changed the title [WIP] Fix binding this to a computed property Fix binding this to a computed property Jun 23, 2019
@Conduitry Conduitry merged commit 01676aa into sveltejs:master Jun 23, 2019
@Conduitry
Copy link
Member

Awesome, thank you so much!

@btk5h btk5h deleted the gh-2333 branch June 23, 2019 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't bind:this a nested component to a dynamic object property
2 participants