Skip to content

Commit

Permalink
7.4. 실전 Redux - action을 dispatch를 통해서 전달하기
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed May 5, 2019
1 parent 7f0988b commit de601f1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ <h1>WEB</h1>
var liTags = '';
while(i<state.contents.length){
liTags = liTags + `
<li>
<a href="${state.contents[i].id}">${state.contents[i].title}</a>
</li>`;
<li>
<a onclick="
event.preventDefault();
var action = {type:'SELECT', id:${state.contents[i].id}}
store.dispatch(action);
" href="${state.contents[i].id}">
${state.contents[i].title}
</a>
</li>`;
i = i + 1;
}
document.querySelector('#toc').innerHTML = `
<nav>
<ol>${liTags}</ol>
<ol>${liTags}</ ol>
</nav>
`;
}
Expand All @@ -53,12 +59,19 @@ <h2>HTML</h2>
function reducer(state, action){
if(state === undefined){
return {
selcted_id:null,
contents:[
{id:1,title:'HTML',desc:'HTML is ..'},
{id:2,title:'CSS', desc:'CSS is ..'}
]
}
}
var newState;
if(action.type === 'SELECT'){
newState = Object.assign({}, state, {selcted_id:action.id});
}
console.log(action, state, newState);
return newState;
}
var store = Redux.createStore(reducer);
subject();
Expand Down

0 comments on commit de601f1

Please sign in to comment.