Skip to content

Commit 5ddbcc2

Browse files
committed
part 7
1 parent f6d436f commit 5ddbcc2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/constants/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const STORY_ARCHIVE = 'STORY_ARCHIVE';

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './components/App';
44
import store from './store';
5+
import { STORY_ARCHIVE } from './constants/actionTypes';
56
import './index.css';
67
import registerServiceWorker from './registerServiceWorker';
78

89
ReactDOM.render(
910
<App
1011
stories={store.getState().storyState}
11-
onArchive={() => {}}
12+
onArchive={id => store.dispatch({ type: STORY_ARCHIVE, id })}
1213
/>,
1314
document.getElementById('root')
1415
);

src/reducers/archive.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import { STORY_ARCHIVE } from '../constants/actionTypes';
2+
13
const INITIAL_STATE = [];
24

5+
const applyArchiveStory = (state, action) =>
6+
[ ...state, action.id ];
7+
38
function archiveReducer(state = INITIAL_STATE, action) {
49
switch(action.type) {
10+
case STORY_ARCHIVE : {
11+
return applyArchiveStory(state, action);
12+
}
513
default : return state;
614
}
715
}

0 commit comments

Comments
 (0)