
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
mergebounce
Advanced tools
A debounce implementation that merges passed in objects before finally sending them to the debounced function
mergebounce is a fork of lodash's debounce function with the added feature that it'll use the lodash merge
function to merge all passed in parameters before eventually invoking the debounced inner function.
By doing so, it's possible to combine multiple expensive calls into a single one without losing state changes that would have been made by individual calls.
npm i mergebounce
Imagine you have a frontend app that stores data in IndexedDB via localForage. Writes to IndexedDB are slow, which can slow down your whole app.
You can increase performance by batching writes together.
One way to do this, is to install localForage-setItems
and then to use mergebounce to combine multple calls to setItems into a
single one.
const debouncedSetItems = mergebounce(
items => store.setItems(items),
50,
{'promise': true}
);
function save (json) {
const items = {}
items[json.id)] = json;
return debouncedSetItems(items);
}
Now save can be called many times, but the actual writes (calls to
setItems) will be far fewer.
Let's suppose you have a chat app and as chat messages appear you want to fetch user data for new message authors.
When you initially load the chat, there might be a 100 messages with 50 authors.
Instead of making a request for every incoming message that has an as yet unknown author, you can mergebounce the function and combine multiple calls into a single request.
For example:
async function _fetchUserData(nicknames) {
const response = await fetch('/user/data', {
body: JSON.stringify({nicknames}),
headers: { 'Content-Type': 'application/json' },
});
data.forEach(userdata => getUser().update(userdata));
}
const fetchUserData = mergebounce(_fetchUserData, 250, {'concatArrays': true});
// The following calls with result in one request with all the nicnames
// concatenated into one array
fetchUserData(['coolguy69', 'ilikecats', 'dielan']);
fetchUserData(['coolboymew']);
fetchUserData(['donkeykong']);
The default debounce options are allowed, as well as the following option:
concatArrays:
By default arrays will be treated as objects when being merged. When
merging two arrays, the values in the 2nd arrray will replace the
corresponding values (i.e. those with the same indexes) in the first array.
When concatArrays is set to true, arrays will be concatenated instead.dedupeArrays:
This option is similar to concatArrays, except that the concatenated
array will also be deduplicated. Thus any entries that are concatenated to the
existing array, which are already contained in the existing array, will
first be removed.promise:
By default, when calling a mergebounced function that doesn't execute
immediately, you'll receive the result from its previous execution, or
undefined if it has never executed before. By setting the promise
option to true, a promise will be returned instead of the previous
execution result when the function is debounced. The promise will resolve
with the result of the next execution, as soon as it happens.FAQs
A debounce implementation that merges passed in objects before finally sending them to the debounced function
The npm package mergebounce receives a total of 160 weekly downloads. As such, mergebounce popularity was classified as not popular.
We found that mergebounce demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.