
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
async-call-reducer
Advanced tools
The AsyncCallReducer
is a function to reduce calls using browser storage. A Promise can be encapsulated, a single HTTP request will be triggered regardless of the number of calls. Concurrent calls are added on a queue and return's data are stored in the browser.
Rules:
The function is available as the async-call-reducer
package name on npm and Github.
npm i --save-dev async-call-reducer
yarn add --dev async-call-reducer
AsyncCallReducer
was built for Node.js >=12
.
The project includes an example of an implementation of AsyncCallReducer
in the directory ./demo/
.
Imagine the following function to get data from an API. Each call will trigger an HTTP request.
async function getData() {
const data = await fetch('https://swapi.dev/api/people/?page=1');
return await data.json();
}
By wrapping the function with the AsyncCallReducer
, a single HTTP request will be triggered. Other calls will return exactly the same value, either from the storage or from the queue if the calls was concurrent.
async function getData() {
+ return await asyncCallReducer({
+ key: 'swapi',
+ callback: async () => {
const data = await fetch('https://swapi.dev/api/people/?page=1');
return await data.json();
+ }
+ });
}
key
string = asyncCallReducer
Tells to the function the storage key used as a prefix. Following keys will be created:
asyncCallReducerData
: Stored dataasyncCallReducerLoading
: Blocker for concurrent callsasyncCallReducer({
key: 'swapi'
});
storage
string = sessionStorage
Tells to the function which browser storage method to use (sessionStorage|localStorage
).
asyncCallReducer({
storage: 'localStorage'
});
callback
Promise
Tells the function the promise to be executed.
💡 Keep the
async
keyword, thecallback
function must returns a Promise.
asyncCallReducer({
callback: async () => {
// Request data from an API and return data here
}
});
AsyncCallReducer
is licensed under the MIT License.
Created with ♥ by @yoriiis.
1.0.0
asyncCallReducer
FAQs
Reduce calls using browser storage
We found that async-call-reducer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.