refactor: isomorphic slices/store
This commit is contained in:
parent
cd279c053f
commit
39539f0154
|
@ -27,6 +27,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@latus/core": "2.0.0",
|
||||
"@latus/socket": "^2.0.0",
|
||||
"@reduxjs/toolkit": "^1.5.0",
|
||||
"debug": "4.3.1",
|
||||
"deepmerge": "^4.2.2",
|
||||
|
@ -38,8 +39,8 @@
|
|||
"devDependencies": {
|
||||
"@neutrinojs/airbnb-base": "^9.4.0",
|
||||
"@neutrinojs/copy": "9.4.0",
|
||||
"@neutrinojs/react": "^9.4.0",
|
||||
"@neutrinojs/mocha": "^9.4.0",
|
||||
"@neutrinojs/react": "^9.4.0",
|
||||
"chai": "4.2.0",
|
||||
"eslint": "^7",
|
||||
"eslint-import-resolver-webpack": "0.13.0",
|
||||
|
|
|
@ -2,14 +2,12 @@ import {combineReducers} from '@reduxjs/toolkit';
|
|||
import {Provider} from 'react-redux';
|
||||
|
||||
import {storageSubscription} from './storage';
|
||||
import gatherSlices from '../slices';
|
||||
import configureStore from '../store';
|
||||
|
||||
export default {
|
||||
hooks: {
|
||||
'@latus/react/client/providers': async (latus) => {
|
||||
const store = await configureStore(latus);
|
||||
const slices = await gatherSlices(latus);
|
||||
const slices = latus.get('%slices');
|
||||
const store = latus.get('%store');
|
||||
const subscriptionReducers = Object.entries(slices).map(([key, slice]) => [
|
||||
key,
|
||||
slice.subscription || (() => null),
|
||||
|
@ -17,8 +15,6 @@ export default {
|
|||
store.subscribe((store) => {
|
||||
storageSubscription(store, combineReducers(subscriptionReducers));
|
||||
});
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
latus.config['%store'] = store;
|
||||
return [Provider, {store}];
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
import {ensureUniqueReduction} from '@latus/core';
|
||||
|
||||
import configureStore from './store';
|
||||
|
||||
export {
|
||||
createAction,
|
||||
createAsyncThunk,
|
||||
|
@ -9,4 +13,11 @@ export {
|
|||
|
||||
export * from 'react-redux';
|
||||
|
||||
export {default as configureStore} from './store';
|
||||
export default {
|
||||
hooks: {
|
||||
'@latus/core/starting': async (latus) => {
|
||||
latus.set('%slices', await ensureUniqueReduction(latus, '@latus/redux/slices'));
|
||||
latus.set('%store', await configureStore(latus));
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import {ensureUniqueReduction} from '@latus/core';
|
||||
|
||||
export default (latus) => ensureUniqueReduction(latus, '@latus/redux/slices');
|
|
@ -3,8 +3,6 @@ import reduceReducers from 'reduce-reducers';
|
|||
|
||||
import effectsMiddleware from './effects';
|
||||
|
||||
import gatherSlices from './slices';
|
||||
|
||||
export default async function configureStore(latus) {
|
||||
const options = {
|
||||
enhancers: [
|
||||
|
@ -17,7 +15,7 @@ export default async function configureStore(latus) {
|
|||
};
|
||||
latus.invokeFlat('@latus/redux/store', options);
|
||||
const {defaultState} = latus.config['@latus/redux/client'];
|
||||
const slices = await gatherSlices(latus);
|
||||
const slices = latus.get('%slices');
|
||||
const reducers = latus.invokeFlat('@latus/redux/reducers').concat(combineReducers(slices));
|
||||
const reducer = reduceReducers({}, ...reducers);
|
||||
return configureStoreR({
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user