Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey,
I'm opening the PR to discuss the
root
property being public (it was briefly discussed in gitter and I'll try to describe the motivation here once again).I have an use case where I'd like to create a new instance of a component with an additional
service
property. The main motivation is easier testing with a fake service, secondary motivation is to make the chat be less dependent on a particular vendor.the chat component itself looks like this:
then inside of the Widget I use the service e.g. to send a message, receive messages etc.:
other approaches I though of or that were suggested to solve this:
a) propagate events from lowest components (e.g. form submits) and handle all of it outside of the chat component - I didn't like it because I'd need to propagate it via many layers, too much hassle, too close to redux kind of way which I find very verbose
b) check if
service
can be passed like thestore
, so that it can be automatically injected into components below - based on discussion in gitter I understood that it seems that dependency injection was discussed before and it's seen as a fragile pattern (I have the same feeling based on what I saw in other libraries, however I also think that it's not necessarily the pattern that is wrong but the excessive use, any pattern is wrong when overused)then the line:
is unnecessary.
c) pass it via
store
asstore.service
. A little bit weird, unexpectedd) pass it via
data
. Weird as well, unexpectedI do understand the desire to keep svelte as concise as possible so I'm open to all suggestions :) Thanks a lot.