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

feat: Implementation of context protocol #4431

Open
3 tasks done
TheCelavi opened this issue May 30, 2023 · 2 comments
Open
3 tasks done

feat: Implementation of context protocol #4431

TheCelavi opened this issue May 30, 2023 · 2 comments
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.

Comments

@TheCelavi
Copy link

Prerequisites

Describe the Feature Request

Lit implements context protocol, see:

Maybe it is a time for StencilJS to join the club and provide its own implementation.

Describe the Use Case

Use cases are well described here: https://lit.dev/docs/data/context/#example-use-cases there is no need to repeat those, just to emphasise that context would be mostly used as replacement for state tunnel when defining local context state in order to avoid prop drilling.

Further possibilities are to create bindings for popular frameworks. Per example, in Angular, Stencil components could query context from DI, in Vue from provider and so on...

Of course - how awesome would be to have both Lit and Stencil components on same page using same context state/service?

Describe Preferred Solution

Implementation could be copied from Lit, with exception that for stencil preferred way to query context would be by using @State() instead of @prop()

@State()
@Consumer(MyService)
public prop?: MyService;

However, this must be allowed too because developer should be allowed to pass dependency as prop :

@Prop()
@Consumer(MyService)
public prop?: MyService;

Describe Alternatives

Alternative approach would be to provide external library with implementation of such functionality.

Related Code

See Lit.

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label May 30, 2023
@alicewriteswrongs alicewriteswrongs added Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. and removed triage labels May 30, 2023
@alicewriteswrongs
Copy link
Contributor

Hey @TheCelavi thanks for filing this feature request! It's an interesting idea and for sure is something to consider how this would fit in to Stencil. I've just labelled this as a feature request so we can gauge community interest in the feature.

Thanks for writing this up!

@TheCelavi
Copy link
Author

@alicewriteswrongs we decided to build it, it should not be hard. However, certain changes are required to provide library with consistent behaviour.

Therefore, I have opened discussion explaining everything: #4872

Would you be willing to check it out and tell me what you think? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.
Projects
None yet
Development

No branches or pull requests

2 participants