Skip to content

Commit f7aca74

Browse files
committed
action creators
1 parent 85dad06 commit f7aca74

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

chapter8/src/actionCreators.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@ export const sortColors = sortedBy =>
1717
(sortedBy === 'rating') ? ({
1818
type:C.SORT_COLORS,
1919
sortedBy : 'SORTED_BY_RATING'
20-
})
20+
}) :
21+
(sortedBy === 'title') ? ({
22+
type : C.SORT_COLORS,
23+
sortBy : 'SORTED_BY_TITLE'
24+
}) : ({
25+
type : C.SORT_COLORS,
26+
sortBy : 'SORTED_BY_DATE'
27+
});
28+
29+
export const addColor = (title, color) => ({
30+
type : C.ADD_COLOR,
31+
id : Math.random()*458723233,
32+
title,
33+
color,
34+
timestamp : new Date.toString()
35+
})
36+
37+
//store.dispatch(addColor('잔디', '#998f12')); 캡슐화 + 디버깅 용이

chapter8/src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const initialState = {
3333

3434
const store =createStore(combineReducers({colors, sort}), (localStorage['redux-store'] ? JSON.parse(localStorage['redux-store']):'')); //localStorage에 값이 있으면
3535

36+
store.subscribe(()=> localStorage['redux-store'] = JSON.stringify(store.getState));
3637
//store.subscribe(()=>console.log('색 개수: ', store.getState().colors.length ));
3738
const logState = ()=>console.log('다음 상태 :', store.getState());
3839
store.subscribe(logState); //함수리스너 등록

0 commit comments

Comments
 (0)