ngneat / cashew

🐿 A flexible and straightforward library that caches HTTP requests in Angular

Home Page:https://www.netbasal.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to chain multiple HttpContext

FabienDehopre opened this issue · comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[X] Support request
[ ] Other... Please describe:

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 ?

withCache() returns the context - use it.

Indeed, it would work if you add new context value after having called withCache() but what if you have other function that also returns a HttpContext?
For instance, we have a library where I'm working that exposes 2 other functions that each returns a HttpContext so to make then "chainable", they both accept a previous HttpContext to reuse it or create a new HttpContext when none is given.

Example:

export function withLoadingSpinner(context: string, previousContext?: HttpContext): HttpContext {
  return (previousContext ?? new HttpContext()).set(LOADING_SPINNER_CONTEXT, context);
}

What about adding something like that to the withCache() function either as a new option value or as an additional parameter?

You're welcome to create a PR