Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
redux-state-sync
Advanced tools
A very light weight middleware to sync your redux state across browser tabs.
Simply install it with npm.
npm install --save redux-state-sync
import { actionStorageMiddleware, createStorageListener } from 'redux-state-sync';
/*
* actionStorageMiddleware is used to persist your last action being triggered.
*/
const middlewares = [
sagaMiddleware,
logger,
actionStorageMiddleware,
routerMiddleware(history),
];
const store = createStore(
createReducer(),
fromJS(initialState),
applyMiddleware(...middlewares)
);
/*
* Create a listener on store to dispatch the latest action being triggered on other tabs.
*/
createStorageListener(store);
You may not want to trigger the Actions which triggers a api request. So you can simply pass in the Action type to ignore it. Like below:
const config = {
ignore: ['CHANGE_USERNAME', 'REPO_REQUEST'],
};
createStorageListener(store, config);
/*
* To still make your state sync. You need to trigger other actions with the data from the api request.
* The example is using redux-saga to handle the side effects.
*/
export function* fetchRepoSaga(action) {
try {
const repo = yield call(api.fetchRepo, action.url);
yield put({ type: 'REPO_SUCCESS', repo });
} catch (e) {
yield put({ type: 'REPO_FAILURE', message: e.message });
}
}
export function* fetchRepoWatcher() {
yield* takeLatest(REPO.REQUEST, fetchRepoSaga);
}
export default [
fetchRepoWatcher,
];
FAQs
A middleware for redux to sync state in different tabs
The npm package redux-state-sync receives a total of 23,003 weekly downloads. As such, redux-state-sync popularity was classified as popular.
We found that redux-state-sync 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.