Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/29/refactor store contents #29

Merged
merged 8 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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';
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');
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
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');
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
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
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>>
};