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

withInjectable and Inject with optional providers. #8

Closed
juanenrisley opened this issue Sep 17, 2018 · 4 comments
Closed

withInjectable and Inject with optional providers. #8

juanenrisley opened this issue Sep 17, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@juanenrisley
Copy link

juanenrisley commented Sep 17, 2018

Feature request

Optional injection feature in "withInjectable" HoC and "Inject" component.

Use case(s)

I just want a way to do optional injection to a react component like using "Optional" decorators. I have an optional injectable service and I do not want the application to crash with the error: "No provider for X!"

@Hotell
Copy link
Owner

Hotell commented Nov 25, 2018

I'm not completely sure I understand the issue here. can you provide codesandbox or at least some code snippet? thanks !

@Hotell
Copy link
Owner

Hotell commented Nov 28, 2018

Hmm, so what you want is basically similar functionality like Angular ElementInjector provides right? To be able to mark injected providers on component level, so that means, covering:

  • @Optional
  • @Self
  • @SkipSelf

@Hotell Hotell added the enhancement New feature or request label Nov 28, 2018
@Hotell
Copy link
Owner

Hotell commented Nov 30, 2018

Following api comes up in my mind:

<Inject values={tuple(ServiceA, optional(ServiceB))} >{
/* $ExpectType [ServiceA, ServiceB | null ] */
(instA, instB)=> { ... }
}</Inject>

WDYT?

  • also just realised that Self and SkipSelf doesn't make any sense as I can't think of real life situation when you would do DependencyProvider with Inject as direct children

@juanenrisley
Copy link
Author

juanenrisley commented Dec 1, 2018

Following api comes up in my mind:

<Inject values={tuple(ServiceA, optional(ServiceB))} >{
/* $ExpectType [ServiceA, ServiceB | null ] */
(instA, instB)=> { ... }
}</Inject>

WDYT?

  • also just realised that Self and SkipSelf doesn't make any sense as I can't think of real life situation when you would do DependencyProvider with Inject as direct children

Yep, that's it. Just what I needed. For the time being, I think that with just @Optional covered is awesome!.

@Hotell Hotell closed this as completed in #10 Dec 5, 2018
Hotell added a commit that referenced this issue Dec 5, 2018
* feat(inject): implement optional

now optional works on component level injection similar to @optional decorator on service layer

* fix(build): implement facade to resolve deps

Closes #8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants