Comments (3)
I think it's not necessary to store those actions which are not allowed. Do you want to send a pull request with the tweak that you did?
from redux-state-sync.
We have some syntactic sugar(wrapper) around the framework, so we made the change in our codebase. We overwrote the middleware portion of your framework. From what I'm seeing, it may require a few changes to the API, I could be mistaken though. Could you checkout my code snippet below and fiddle around with some ideas on how you would like to accomplish this?
// TabSyncMiddleware.js
import { createStorageListener, withReduxStateSync } from 'redux-state-sync';
import ActionWhiteList from './ActionWhiteList'; // actions we want to sync across tabs
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
function guid() {
return `${s4()}-${s4()}-${s4()}-${s4()}-${s4()}-${s4()}-${s4()}-${s4()}`;
}
export const reducerTabSync = withReduxStateSync;
export const tabSyncMiddleware = ({ getState }) => (next) => (action) => {
if (action && !action.$uuid) {
const stampedAction = {
$uuid: guid(),
...action
};
try {
if (action.type === '&_SEND_INIT_STATE') {
if (getState()) {
stampedAction.payload = getState();
localStorage.setItem('LAST_ACTION', JSON.stringify(stampedAction));
}
return next(action);
}
if (ActionWhiteList.includes(action.type)) { // here's the part we needed
localStorage.setItem('LAST_ACTION', JSON.stringify(stampedAction));
}
} catch (e) {
console.error('Failed to store `LAST_ACTION` to localStorage.');
}
}
return next(action);
};
export const TabSyncWrapper = (store) => {
createStorageListener(store, {
initiateWithState: true,
predicate: (actionType) => {
return ActionWhiteList.includes(actionType);
}
});
return store;
};
Usage
// index.js
import { tabSyncMiddleware, TabSyncWrapper, reducerTabSync } from './middleware/TabSyncMiddleware';
// ...
const enhancer = composeEnhancers(
applyMiddleware( ..., ..., tabSyncMiddleware)
);
const store = TabSyncWrapper(createStore(
reducerTabSync(reducers),
enhancer
));
// ...
render(
<Provider store={store}>
<AppRouter />
</Provider>,
document.getElementById('root')
);
from redux-state-sync.
Sorry for the long delay, I just released redux-state-sync 2.0, Your problem should be fixed in the new version.
from redux-state-sync.
Related Issues (20)
- How to disable initial application loading if synced HOT 3
- Init tab with partial state HOT 2
- immutable but only for parts of the state
- redux persist "and" sync HOT 1
- Allow to omit certain fields from actions on broadcast
- Test cases fails with message "input is invalid type" HOT 2
- Old version of broadcast-channel dependency causing issues HOT 3
- Configuration with redux-toolkit HOT 4
- Broadcast channels not systematically closed ? Leak ? HOT 3
- Export critical variables HOT 1
- Error after adding the package @types/redux-state-sync HOT 1
- Use with ConfigureStore() HOT 2
- Feature request: don't sync between different Firefox containers
- How to stop/disable/pause syncing? HOT 1
- Memory Leak on Azure
- Lighthouse audit fails with `no-unload-listeners`
- Parent Tab Stops Working
- Locally syncing the results of Async actions.. how does this work here? HOT 6
- TypeScript typing wrong in returned store after wrapping reducers with withReduxStateSync() HOT 1
- Feature Request: modify actions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-state-sync.