This library aims to deduplicate repetitive call to the server while the request is still pending and pass the same promise to callers.
Almost always.
Say you have a button that calls the server then process the response and does something, but then the user -or any other scenario- clicked the button three times, that's three calls to server to do the same thing.
Our service can provide caching the promise and dispatching the same promise to all three calls.
npm i angular-request-dedup
Integrate in the angular app
angular.module("app", ["angular-request-dedup"])
class MainResource {
constructor(AngularRequestDedup) {
this.AngularRequestDedup = AngularRequestDedup;
}
getAll(params) {
return this.AngularRequestDedup.dedup(url).get(params)
}
}
- Once the promise is resolved, the promise is discarded from the cache.
- You can pass
isPersistent
flag in the params object to keep the promise in the app state.
- It works with minium of AngualrJs 1.5.x
- Any bundler would do, no need for special loaders