Skip to content

Commit

Permalink
feat(store/reducers/products): apply correct strict typing
Browse files Browse the repository at this point in the history
import all types from 'store/types'
  • Loading branch information
aneurysmjs committed May 23, 2019
1 parent 5f27a98 commit 4d8eb97
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/app/store/reducers/products.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// @flow strict
import type { Action } from 'redux';

import type { Response } from '@/store/types/CommonType';
import type { ProductType } from '@/store/types/ProductsType';

import createReducer from './createReducer';

import { GET_PRODUCTS_SUCCESS } from '../ActionTypes';

export default createReducer([], {
type ProductsType = Array<ProductType>;

type ProductActionType = {
...$Exact<Action<string>>,
...$Exact<Response<ProductsType>>
};

export default createReducer<ProductsType, ProductActionType>([], {
[GET_PRODUCTS_SUCCESS](state, action) {
const {
response: {
Expand All @@ -13,4 +24,4 @@ export default createReducer([], {
} = action;
return [...data];
}
});
});
7 changes: 7 additions & 0 deletions src/app/store/types/CommonType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow strict

export type Response<D> = {
response: {
data: D
}
};
12 changes: 12 additions & 0 deletions src/app/store/types/ProductsType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow strict

export type ProductType = {
_id: string,
name: string,
image: string,
imageHovered: string,
description: string,
price: number,
stock: number,
shop: string,
};

0 comments on commit 4d8eb97

Please sign in to comment.