Skip to content

Commit

Permalink
Merge pull request #29 from aneurysmjs/issue/28/refactor-store-contents
Browse files Browse the repository at this point in the history
Issue/29/refactor store contents
  • Loading branch information
aneurysmjs authored Aug 29, 2019
2 parents ba43d7b + fffb99a commit 9f7d3aa
Show file tree
Hide file tree
Showing 48 changed files with 44 additions and 40 deletions.
3 changes: 3 additions & 0 deletions config/webpack-config/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ module.exports = {
api$: `${paths.srcApp}/api/api.js`,
'@': paths.srcApp,
styles: `${paths.srcApp}/assets/scss`,
// @link https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
},
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"start": "cross-env NODE_ENV=development node scripts/start.js",
"start:analyzer": "webpack-bundle-analyzer build/client/static/bundle-stats.json",
"test": "node scripts/test.js --env=jsdom",
"test:update": "yarn test --updateSnapshot",
"flow-typed": "node_modules/.bin/flow-typed",
"lint:js": "eslint src/**/*.{js}",
"semantic-release": "semantic-release"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/core/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
// $FlowIgnore
import { useSelector } from 'react-redux';

import { getFooter } from '@/store/reducers/footer';
import { getFooter } from '@/store/modules/footer/selectors';
import type { FooterType } from '@/store/types/FooterType';

import Icon from '@/components/base/Icon/Icon';
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/core/UserMenu/UserMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux';

import Icon from '@/components/base/Icon/Icon';
import { useLazy } from '@/hooks/useLazy';
import { getCart } from '@/store/reducers/cart';
import { getCart } from '@/store/modules/cart/selectors';

import type { CartType } from '@/store/types/CartType';

Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import Spinner from '@/components/base/Spinner/Spinner';
import { fetchProducts } from '@/store/actions';
import { getProducts } from '@/store/selectors/getProducts';
import { fetchProducts } from '@/store/modules/products/actions';
import { getProducts } from '@/store/modules/products/selectors';
import type { ProductsType } from '@/store/types/ProductsType';

import ProductCard from '@/components/shared/ProductCard/ProductCard';
Expand Down
4 changes: 0 additions & 4 deletions src/app/store/actions/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type { Actions } from '@/store/types/Actions';
// import throttle from 'lodash.throttle';

// Middleware is the suggested way to extend Redux with custom functionality.
import middlewares from '@/store/middlewares';
import middlewares from '@/store/config/middlewares';

// import all reducers
import reducer from '@/store/reducers';

// import { saveState, loadState } from './localStorage';
// import { saveState, loadState } from './storage';

// Get the state from localStorage
// const persistedState = loadState();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/app/store/helpers/createReducer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { default as createReducer } from './createReducer';
3 changes: 3 additions & 0 deletions src/app/store/helpers/makeActionCreator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { default as makeActionCreator } from './makeActionCreator';
File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/store/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow strict

import configureStore from './configureStore';
import configureStore from './config/configureStore';

const store = configureStore();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow strict
import * as types from '@/store/ActionTypes';

import makeActionCreator from '@/store/actions/makeActionCreator';
import { makeActionCreator } from '@/store/helpers/makeActionCreator';

export default makeActionCreator(types.CART_DATA, 'cart');
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CartType, CartActionType } from '@/store/types/CartType';

import { CART_DATA } from '@/store/ActionTypes';

import createReducer from '../createReducer';
import { createReducer } from '@/store/helpers/createReducer';

const initialState = {
quantity: 0,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/app/store/modules/cart/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { default as cart } from './cart';
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @flow strict

import type { State } from '@/store/types/State';

import cart from './cart';

export default cart;

// eslint-disable-next-line import/prefer-default-export
export const getCart = (state: State) => state.cart;
3 changes: 3 additions & 0 deletions src/app/store/modules/cart/selectors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { getCart } from './getCart';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow strict
import * as types from '@/store/ActionTypes';

import makeActionCreator from '@/store/actions/makeActionCreator';
import { makeActionCreator } from '@/store/helpers/makeActionCreator';

export default makeActionCreator(types.FOOTER_DATA, 'footer');
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import type { FooterType, FooterActionType } from '@/store/types/FooterType';

import { FOOTER_DATA } from '@/store/ActionTypes';
import type { State } from '@/store/types/State';

import createReducer from '../createReducer';
import { createReducer } from '@/store/helpers/createReducer';

const initialState = {
social: [
Expand All @@ -20,5 +19,3 @@ export default createReducer<FooterType, FooterActionType>(initialState, {
};
},
});

export const getFooter = ({ footer }: State) => footer;
3 changes: 3 additions & 0 deletions src/app/store/modules/footer/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { default as footer } from './footer';
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @flow strict

import type { State } from '@/store/types/State';

import footer from './footer';

export default footer;

// eslint-disable-next-line import/prefer-default-export
export const getFooter = (state: State) => state.footer;
3 changes: 3 additions & 0 deletions src/app/store/modules/footer/selectors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { getFooter } from './getFooter';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { State } from '@/store/types/State';
import type { AsyncAction } from '@/store/types/Actions';
import type { ProductsType } from '@/store/types/ProductsType';

import { getProducts } from '@/store/selectors/getProducts';
import { getProducts } from '@/store/modules/products/selectors';

export default function fetchProducts(query: string = ''): AsyncAction<State> {
return {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @flow strict
import type { ProductsType, ProductActionType } from '@/store/types/ProductsType';

import createReducer from '../createReducer';
import { createReducer } from '@/store/helpers/createReducer';

import {
GET_PRODUCTS_FAILURE,
GET_PRODUCTS_REQUEST,
GET_PRODUCTS_SUCCESS,
} from '../../ActionTypes';
} from '@/store/ActionTypes';

const initialState = {
error: null,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/app/store/modules/products/selectors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { getProducts } from './getProducts';
9 changes: 3 additions & 6 deletions src/app/store/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// @flow strict
/**
* @module reducers
*/

import { combineReducers } from 'redux';

import type { Actions } from '@/store/types/Actions';

import cart from './cart';
import footer from './footer';
import { products } from './products';
import { footer } from '@/store/modules/footer/reducers';
import { cart } from '@/store/modules/cart/reducers';
import { products } from '@/store/modules/products/reducers';

export default combineReducers<{}, Actions>({
cart,
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/types/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export type AsyncAction<S> = {

export type MiddlewareAction<S> = {
type: string,
...AsyncAction<S>
...$Exact<AsyncAction<S>>
};

0 comments on commit 9f7d3aa

Please sign in to comment.