Skip to content
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

component.set({ foo: undefined }) should 'unset' foo #1488

Closed
Rich-Harris opened this issue May 24, 2018 · 3 comments
Closed

component.set({ foo: undefined }) should 'unset' foo #1488

Rich-Harris opened this issue May 24, 2018 · 3 comments
Labels
Milestone

Comments

@Rich-Harris
Copy link
Member

In the following case...

<svelte:component this={Whatever} bind:foo/>

...it's very likely that when Whenever changes, you don't want the new component to have the value of foo from the old component imposed upon it. But if you try to clear the value...

this.set({ foo: undefined });
this.set({ Whatever: SomeNewComponent });

...then the SomeNewComponent instance is initialised with foo: undefined rather than being able to use its default value, which is what you want in that situation. The workaround is somewhat hacky:

delete this._state.foo;
this.set({ Whatever: SomeNewComponent });

I'd argue that the current behaviour is a bug, and that undefined values should be deleted from the state object automatically. Outside of the <svelte:component> case, I don't think it would result in any different outcomes.

@Rich-Harris
Copy link
Member Author

We might not need this, because of #1490

@eyeseast
Copy link

Would it make sense to have a this.del('key') that explicitly removes a key from state? (Though in all honestly, I can't think of when I've actually needed this.)

@Rich-Harris
Copy link
Member Author

In Svelte 3 we seem to have the opposite bug — the child value always overrides the parent value https://v3.svelte.technology/repl?version=3.0.0-alpha12&gist=181691a0863f4a40fd80f05ba81736b5

@Rich-Harris Rich-Harris added this to the 3.x milestone Dec 31, 2018
Rich-Harris added a commit that referenced this issue Jan 20, 2019
Fix props for logic-less components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants