Skip to content

Commit d1c00b7

Browse files
Renames colors to posts
1 parent 27cd24c commit d1c00b7

File tree

10 files changed

+46
-46
lines changed

10 files changed

+46
-46
lines changed

src/store/colors/actions.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/store/colors/constants.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/store/colors/state.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/store/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import thunk from 'redux-thunk';
22
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
33
import { browserHistory } from 'react-router';
44
import { counterReducer } from './counter';
5-
import { colorsReducer, fetchColors } from './colors';
5+
import { postsReducer, fetchPosts } from './posts';
66

77
const { syncHistoryWithStore, routerReducer } = require('react-router-redux');
88

@@ -17,7 +17,7 @@ if (DEVELOPMENT) {
1717

1818
const reducer = combineReducers({
1919
counter: counterReducer,
20-
colors: colorsReducer,
20+
colors: postsReducer,
2121
routing: routerReducer
2222
});
2323
const initialState = {};
@@ -27,6 +27,6 @@ const store = createStore(reducer, initialState, enhancer);
2727
// Create an enhanced history that syncs navigation events with the store
2828
const history = syncHistoryWithStore(browserHistory, store);
2929

30-
store.dispatch(fetchColors());
30+
store.dispatch(fetchPosts());
3131

3232
export { store, history };

src/store/posts/actions.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { REQUEST_POSTS, RECEIVE_POSTS, IPost } from './';
2+
import { IAction, IThunk, IData } from '../interfaces';
3+
import fetch from 'isomorphic-fetch';
4+
5+
export interface IPostsAction extends IAction {
6+
items: Array<IPost>;
7+
}
8+
9+
export function requestPosts(): IPostsAction {
10+
return { type: REQUEST_POSTS, items: null };
11+
}
12+
13+
export function receivePosts(json: IData): IPostsAction {
14+
return { type: RECEIVE_POSTS, items: json.data };
15+
}
16+
17+
export function fetchPosts(): IThunk {
18+
return function(dispatch) {
19+
dispatch(requestPosts());
20+
return fetch('/fixtures/posts.json')
21+
.then(response => response.json())
22+
.then(json => dispatch(receivePosts(json)));
23+
};
24+
}

src/store/posts/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const REQUEST_POSTS: string = 'REQUEST_POSTS';
2+
export const RECEIVE_POSTS: string = 'RECEIVE_POSTS';
File renamed without changes.

src/store/colors/reducer.ts renamed to src/store/posts/reducer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {
2-
RECEIVE_COLORS,
3-
REQUEST_COLORS,
4-
IColorsState,
5-
IColorAction,
2+
RECEIVE_POSTS,
3+
REQUEST_POSTS,
4+
IPostsState,
5+
IPostsAction,
66
} from './';
77

8-
const initialState: IColorsState = {
8+
const initialState: IPostsState = {
99
isFetching: false,
1010
items: [],
1111
};
1212

13-
export function colorsReducer(state: IColorsState = initialState, action: IColorAction): IColorsState {
13+
export function postsReducer(state: IPostsState = initialState, action: IPostsAction): IPostsState {
1414
switch (action.type) {
15-
case RECEIVE_COLORS:
15+
case RECEIVE_POSTS:
1616
return Object.assign({}, state, { items: action.items, isFetching: false });
17-
case REQUEST_COLORS:
17+
case REQUEST_POSTS:
1818
return Object.assign({}, state, { isFetching: true });
1919
default:
2020
return state;

src/store/posts/state.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface IPost {
2+
color: string;
3+
value: string;
4+
}
5+
6+
export interface IPostsState {
7+
isFetching: boolean;
8+
items: Array<IPost>;
9+
}
File renamed without changes.

0 commit comments

Comments
 (0)