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: allow passing existing HttpContext to withCache function #43

Merged
merged 7 commits into from Jul 11, 2021
Merged

feat: allow passing existing HttpContext to withCache function #43

merged 7 commits into from Jul 11, 2021

Conversation

FabienDehopre
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: CONTRIBUTING.md#commit
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

When you use the withCache() function in a HttpClient method, it needs to be assigned to the context option. How do you add something else to the HttpRequest context ?

Issue Number: #42

What is the new behavior?

Add a second argument to withCache function to pass an optional existing HttpContext returned from another function (similar to withCache).
If the existing HttpContext has been provided, the function will use it; otherwise, the function will create a new HttpContext.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

README.md Outdated Show resolved Hide resolved
README.md Outdated
}
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention the alternative way.

@@ -16,8 +16,8 @@ export interface ContextOptions {

export const CACHE_CONTEXT = new HttpContextToken<ContextOptions>(() => ({}));

export function withCache(options: ContextOptions = {}) {
return new HttpContext().set(CACHE_CONTEXT, {
export function withCache(options: ContextOptions = {}, existingHttpContext?: HttpContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to add it as an option. I don't like the withCache({}, context) style.

Take it from the options and delete it afterward.

@FabienDehopre
Copy link
Contributor Author

I've already updated the code by moving the second argument to the option object (and removing it).
However, I still have to update the documentation (README.md). I'll do it ASAP tomorrow.

@FabienDehopre
Copy link
Contributor Author

@NetanelBasal I've updated the readme can you have a look and tell me if it's ok or not ?

@NetanelBasal NetanelBasal merged commit cd788d5 into ngneat:master Jul 11, 2021
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.

2 participants