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

Detect when dynamic components are in components and not data #1039

Closed
Rich-Harris opened this issue Dec 22, 2017 · 2 comments
Closed

Detect when dynamic components are in components and not data #1039

Rich-Harris opened this issue Dec 22, 2017 · 2 comments

Comments

@Rich-Harris
Copy link
Member

This is incorrect, but it's not immediately obvious why (it took me a while to figure out).

The component constructors need to be in data, not componentslike this. Is there a way to detect that mistake and warn on it?

@ekhaled
Copy link
Contributor

ekhaled commented Dec 22, 2017

Do they have to be in data?
I mean, can we not find a way around of leaving them in components.

I suppose this might mean components keeping track of all their children, but that might be better in the long run when HMR is introduced (maybe)

@Rich-Harris
Copy link
Member Author

can we not find a way around of leaving them in components

The short answer is 'no', it's not possible. The longer answer: if you had something like this...

<VirtualList component={{Item}} height=500/>

...then inside the <VirtualList> component you'd have something like this:

{{#each visibleItems as item}}
  <:Component {component} :item/>
{{/each}}

The parent component would have no knowledge that component was a special property and that Item should therefore come from components and not data, and the child component wouldn't have access to Item other than as data.

This is one of those things where something that initially seems like it would reduce confusion would end up creating a lot more. It's better if we just have one concept for this, and try and come up with ways to guide people towards the correct understanding — such as a dev-time warning that lets you know that Item was on Svelte's internal expectedProperties list and is present on components (where it is unused) but not on the initial state object created from data.

Rich-Harris added a commit that referenced this issue Dec 30, 2017
detect unused/misplaced components
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

No branches or pull requests

2 participants