Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
redux-batched-subscribe
Advanced tools
redux store enhancer which allows batching subscribe notifications.
Store enhancer for redux which allows batching of subscribe notifications that occur as a result of dispatches.
npm install --save redux-batched-subscribe
The batchedSubscribe
store enhancer accepts a function which is called after every dispatch with a notify
callback as a single argument. Calling the notify
callback will trigger all the subscription handlers, this gives you the ability to use various techniques to delay subscription notifications such as: debouncing, React batched updates or requestAnimationFrame.
Since batchedSubscribe
overloads the dispatch and subscribe handlers on the original redux store it is important that it gets applied before any other store enhancers or middleware that depend on these functions; The compose utility in redux can be used to handle this:
import { createStore, applyMiddleware, compose } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';
const enhancer = compose(
applyMiddleware(...middleware),
batchedSubscribe((notify) => {
notify();
})
)
// Note: passing enhancer as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, initialState, enhancer);
Note: since compose
applies functions from right to left, batchedSubscribe
should appear at the end of the chain.
The store enhancer also exposes a subscribeImmediate
method which allows for unbatched subscribe notifications.
import { createStore } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';
import debounce from 'lodash.debounce';
const batchDebounce = debounce(notify => notify());
const finalCreateStore = batchedSubscribe(batchDebounce)(createStore);
const store = finalCreateStore(reducer, intialState);
import { createStore } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';
// React <= 0.13
import { addons } from 'react/addons';
const batchedUpdates = addons.batchedUpdates;
// React 0.14
import { unstable_batchedUpdates as batchedUpdates } from 'react-dom';
// Note: passing batchedSubscribe as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, intialState, batchedSubscribe(batchedUpdates));
Thanks to Andrew Clark for the clean library structure.
FAQs
redux store enhancer which allows batching subscribe notifications.
The npm package redux-batched-subscribe receives a total of 0 weekly downloads. As such, redux-batched-subscribe popularity was classified as not popular.
We found that redux-batched-subscribe 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.