-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
README.md
Outdated
} | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Co-authored-by: Netanel Basal <[email protected]>
I've already updated the code by moving the second argument to the option object (and removing it). |
@NetanelBasal I've updated the readme can you have a look and tell me if it's ok or not ? |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
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 existingHttpContext
returned from another function (similar towithCache
).If the existing
HttpContext
has been provided, the function will use it; otherwise, the function will create a newHttpContext
.Does this PR introduce a breaking change?
Other information