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

Reduce duplication of code #1723

Closed
StarpTech opened this issue Sep 11, 2018 · 10 comments

Comments

@StarpTech
Copy link
Contributor

commented Sep 11, 2018

Hi, based on the fact that svelte has no runtime how do you avoid that the skeleton code (e.g bootstrap code, util functions, browser tweaks) isn't shipped with every component? I understand that each component should be a self contained application but in reality I have hundreds of components in a single project. Did you ever measure this overhead? Do you think its worth to split it up for really big projects? Thanks.

@paulocoghi

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

This is one of the issues that Sapper solves. You can include util functions and other things only once and use them on desired components without duplication.

@StarpTech

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2018

Hi @paulocoghi thanks for the link but I don't talk about PWA's or project specific dependencies. My question is about the code generation.

@tivac

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

If you use a bundler it'll handle the util deduping for you as part of the usual module deduping process.

@StarpTech

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2018

My question is more an internal thing. When I look at the output of an component, you can see some boilerplate. Is it possible or does exists plans to reduce it even further?

@tivac

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

Could you share some examples of the component code you consider boilerplate?

@StarpTech

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2018

For example https://svelte.technology/repl?version=2.13.4&demo=hello-world

  • assign
  • setDev
  • on
  • fire
  • _set
  • destroy
  • flush
  • insert
  • detach
  • differs
  • append

are util functions which will land in every component. If we could provide an options to deliver it in a separate file it would save a lot of space. Please have in mind that I'm talking about a scenario with lots of components 100+. This is no issue I just want to know if it was already considered.

@tivac

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

Those are the exact methods that won't be duplicated when using a bundler. They come from https://github.com/sveltejs/svelte/blob/master/src/shared/index.js and there will only be one copy of that for any number of components.

Try adding another component in the REPL by adding another file and referencing it from the default. That boilerplate won't be repeated.

@StarpTech

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2018

Awesome! It's definitely worth to mention it in the docs. If you hear "no runtime" you will always think about duplication but this isn't the case.

@paulocoghi

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

Initially Svelte worked this way, and there were "no runtime". But because of the duplication issue, the "standalone vs non-standalone" dilemma was solved with the shared code solution/deduplication, which later became enabled by default.

@StarpTech

This comment has been minimized.

Copy link
Contributor Author

commented Sep 12, 2018

@paulocoghi thanks for pointing out.

@StarpTech StarpTech closed this Sep 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.