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(assert-injector): add assertInjector #17

Merged
merged 1 commit into from
Sep 11, 2023
Merged

Conversation

nartc
Copy link
Collaborator

@nartc nartc commented Sep 11, 2023

closes #16

This PR adds a utility function assertInjector that abstracts assertInInjectionContext and guarantees an Injector after the utility is invoked

function injectDummy(injector?: Injector) {
  injector = assertInjector(injectDummy, injector);
  // ^ injector is guaranteed to be an Injector
  runInInjectionContext(injector, () => {
    // always run in a particular Injector's context
  })
}

@nartc nartc requested a review from eneajaho September 11, 2023 02:43
@nartc nartc self-assigned this Sep 11, 2023
@nx-cloud
Copy link

nx-cloud bot commented Sep 11, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 16a3724. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

closes #15

This PR adds a utility function `assertInjector` that abstracts `assertInInjectionContext` and guarantees an `Injector` after the utility is invoked

```ts
function injectDummy(injector?: Injector) {
  injector = assertInjector(injectDummy, injector);
  // ^ injector is guaranteed to be an Injector
  runInInjectionContext(injector, () => {
    // always run in a particular Injector's context
  })
}
```
@eneajaho
Copy link
Collaborator

LGTM

Nit: we need to add comments to these functions so the devs can se the usage example directly in the dts files

@nartc nartc merged commit e1570a6 into main Sep 11, 2023
5 checks passed
@nartc nartc deleted the feat/assert-injector branch September 11, 2023 08:20
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

Successfully merging this pull request may close these issues.

[feat] add assertInjector
2 participants