Skip to content

This library aims to cache repetitive call to the server while the request is still pending and pass the same promise to callers.

License

Notifications You must be signed in to change notification settings

AndrewLawendy/angular-request-dedup

Repository files navigation

angular-request-dedup

This library aims to deduplicate repetitive call to the server while the request is still pending and pass the same promise to callers.

GitHub GitHub package.json version npm GitHub file size in bytes

NPM

When to use it

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.

How to use

npm i angular-request-dedup

Integrate in the angular app angular.module("app", ["angular-request-dedup"])

Example

class MainResource {
    constructor(AngularRequestDedup) {
        this.AngularRequestDedup = AngularRequestDedup;
    }

    getAll(params) {
        return this.AngularRequestDedup.dedup(url).get(params)
    }
}

Highlights

  1. Once the promise is resolved, the promise is discarded from the cache.
  2. You can pass isPersistent flag in the params object to keep the promise in the app state.

Prerequisites

  • It works with minium of AngualrJs 1.5.x
  • Any bundler would do, no need for special loaders

About

This library aims to cache repetitive call to the server while the request is still pending and pass the same promise to callers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published