Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
fix(#133): revert redux bundle split
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Gasser authored and Andreas Gasser committed May 28, 2019
1 parent 35a4b74 commit 52d612a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 95 deletions.
11 changes: 2 additions & 9 deletions src/images/detail/Container.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { connect } from 'react-redux';

import imagesReducer, { getImage } from '../../redux/images';
import labelsReducer from '../../redux/labels';
import facesReducer from '../../redux/faces';
import { imagesByIdSelector, getImageRequestSelector } from '../../redux/images/selectors';

import { labelsByImageIdSelector, labelsByIdSelector } from '../../redux/labels/selectors';
import { facesByImageId, facesByIdSelector } from '../../redux/faces/selectors';

import DetailView from './DetailView';
import getStore from '../../redux/getStore';
import { getImage } from '../../redux/images';

const { store } = getStore();
store.injectReducer('images', imagesReducer);
store.injectReducer('labels', labelsReducer);
store.injectReducer('faces', facesReducer);
import DetailView from './DetailView';

const mapKeyToValue = (searchString) => {
const params = {};
Expand Down
7 changes: 1 addition & 6 deletions src/images/list/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import { connect } from 'react-redux';

import { sortedImageListSelector, addImageRequestSelector } from '../../redux/images/selectors';

import imagesReducer, { listImages } from '../../redux/images';
import { listImages } from '../../redux/images';

import ListView from './ListView';

import getStore from '../../redux/getStore';

const { store } = getStore();
store.injectReducer('images', imagesReducer);

const select = state => ({
images: sortedImageListSelector(state),
addImageRequest: addImageRequestSelector(state),
Expand Down
57 changes: 0 additions & 57 deletions src/redux/__tests__/configureStore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,60 +186,3 @@ describe('redux getErrorOptions test sutie', () => {
expect(store.getActions()).toEqual(expectedActions);
});
});

describe('dynamic reducer creation test suite', () => {
let store;

beforeEach(() => {
store = configureStore().store; // eslint-disable-line prefer-destructuring
});

it('should be initialized with empty dynamic reducer and injectReducer function', () => {
expect(store.injectReducer).toBeInstanceOf(Function);
expect(store.asyncReducers).toEqual({});
});

it('should add new reducer to redux tree', () => {
const replaceReducerCallback = jest.fn();
const demoReducerCallback = jest.fn();

store.replaceReducer = replaceReducerCallback;

expect(replaceReducerCallback).not.toHaveBeenCalled();

const demoReducer = () => {
demoReducerCallback();
return null;
};
store.injectReducer('demo', demoReducer);

expect(Object.keys(store.asyncReducers)).toEqual(['demo']);
expect(store.asyncReducers.demo).toEqual(demoReducer);

expect(replaceReducerCallback).toHaveBeenCalled();
});

it('should not add new reducer to redux tree if already added', () => {
const replaceReducerCallback = jest.fn();
const demoReducerCallback = jest.fn();

store.replaceReducer = replaceReducerCallback;

expect(replaceReducerCallback).not.toHaveBeenCalled();

const demoReducer = () => {
demoReducerCallback();
return null;
};
store.injectReducer('demo', demoReducer);

expect(Object.keys(store.asyncReducers)).toEqual(['demo']);
expect(store.asyncReducers.demo).toEqual(demoReducer);

expect(replaceReducerCallback).toHaveBeenCalledTimes(1);

store.injectReducer('demo', demoReducer);
expect(Object.keys(store.asyncReducers)).toEqual(['demo']);
expect(replaceReducerCallback).toHaveBeenCalledTimes(1);
});
});
10 changes: 9 additions & 1 deletion src/redux/__tests__/rootReducer.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import rootReducer from '../rootReducer';

describe('root reducer test suite', () => {
const firstLevelKeys = ['appTime', 'application', 'auth'];
const firstLevelKeys = [
'appTime',
'application',
'auth',
'images',
'labels',
'faces',
'user',
];

it('should return root redux object tree', () => {
expect(Object.keys(rootReducer)).toEqual(firstLevelKeys);
Expand Down
16 changes: 0 additions & 16 deletions src/redux/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,6 @@ const configureStore = (initialState = {}) => {
// add error handler
addUnhandledPromiseCatcher(store);

/**
* Enable redux reducer split.
* Implementation details found here: https://redux.js.org/recipes/code-splitting
*/
// Add a dictionary to keep track of the registered async reducers
store.asyncReducers = {};

// Create an inject reducer function
// This function adds the async reducer, and creates a new combined reducer
store.injectReducer = (key, asyncReducer) => {
if (!store.asyncReducers[key]) {
store.asyncReducers[key] = asyncReducer;
store.replaceReducer(createReducer(store.asyncReducers));
}
};

return {
store,
persistor,
Expand Down
8 changes: 8 additions & 0 deletions src/redux/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import applicationReducer from './application';
import authReducer from './auth';
import imagesReducer from './images';
import labelsReducer from './labels';
import facesReducer from './faces';
import userReducer from './user';

const staticReducers = {
/**
Expand All @@ -10,6 +14,10 @@ const staticReducers = {
appTime: () => Date.now(),
application: applicationReducer,
auth: authReducer,
images: imagesReducer,
labels: labelsReducer,
faces: facesReducer,
user: userReducer,
};

export default staticReducers;
7 changes: 1 addition & 6 deletions src/user/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import { connect } from 'react-redux';
import { logOutUser } from '../redux/auth';
import { authMetaSelector } from '../redux/auth/selectors';

import userReducer, { getUserInfo, updateUser } from '../redux/user';
import { getUserInfo, updateUser } from '../redux/user';
import { getUserInfoRequestSelector, updateUserRequestSelector, userSelector } from '../redux/user/selectors';

import UserView from './UserView';

import getStore from '../redux/getStore';

const { store } = getStore();
store.injectReducer('user', userReducer);

const select = state => ({
user: userSelector(state),
getUserInfoRequest: getUserInfoRequestSelector(state),
Expand Down

0 comments on commit 52d612a

Please sign in to comment.