Patterns that should be implemented using saga slice for best results
Building apps can be messy
It's even messier with 4 boilerplate files, which is why saga-slice exists. Even then, things can still get messy, which is why this conventions page exists. Ultimately, we all do whatever we understand, but I have found that following a guideline increases focus and reduces entropy quite a bit.
I have seen 2 common sense patterns implemented in redux which are formidable:
Pattern A: implement the conventions suggested by the official redux guides
Pattern B: create all redux stuff inside of a corresponding component folder
In either case, we should consider separating store config, react config, and module declaration so we can leave the particularities of each inside its own node module. What that means is:
Pattern A ./modules/index.js or Pattern B ./modules.js
Both should only worry about importing the saga slice modules and not couple store instantiation logic inside of here. This allows for this file to be the source of truth for declaring saga slices. It can grow as much as it needs to without logic clutter.
This file should only contain all the logic relating to redux instantiation. This means that it should not be coupled with react logic at all. The reasoning for this is because code can get messy when wiring up your redux store, and it can get equally as messy for wiring up react initialization.
import { createStore, applyMiddleware, compose } from'redux';import createSagaMiddleware from'redux-saga';import { connectRouter } from'connected-react-router';import { rootSaga, rootReducer } from'saga-slice';// This is where you would bring in your array of saga slices or any other// map of extra reducers.import reduxModules from'./modules';import history from'./utils/history';constsagaMiddleware=createSagaMiddleware();constcomposeEnhancers=window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;exportconststore=createStore(rootReducer(reduxModules, {// Extra reducers router:connectRouter(history) }),composeEnhancers(applyMiddleware(sagaMiddleware)));exportconst { getState,dispatch,subscribe } = store;sagaMiddleware.run(rootSaga(reduxModules));exportdefault store;
File ./index.js
This file should be focused on the logic relating to react initialization. This includes any routing you might want to implement if that's a thing in this file, etc.
In conclusion, I sincerely hope you understand the reasoning behind these suggested conventions. We want to keep our code base focused, organized, and scalable.