Skip to content

Commit

Permalink
tutorial learncodeacademy#3 was followed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimmi Weeraddana authored and Nimmi Weeraddana committed Mar 13, 2017
1 parent 5c1a89a commit 53a09a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions 1-basic-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"babel-preset-stage-0": "^6.3.13",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"redux": "^3.6.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.1"
},
Expand Down
27 changes: 25 additions & 2 deletions 1-basic-react/src/js/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import React from "react";
/*import React from "react";
import ReactDOM from "react-dom";
import Layout from "./components/Layout";
const app = document.getElementById('app');
ReactDOM.render(<Layout/>, app);
ReactDOM.render(<Layout/>, app);*/

import { createStore } from "redux";

const reducer = function(state, action) {
if(action.type == 'INC'){
return state + action.payload;
}
if(action.type == 'DEC'){
return state - action.payload;
}
return state;
}

const store = createStore(reducer, 0);

store.subscribe(() => {
console.log('store changed',store.getState())
})

store.dispatch({type: 'INC', payload:1}) //run through reducer
store.dispatch({type: 'DEC', payload:1})
store.dispatch({type: 'DEC', payload:100})
store.dispatch({type: 'INC', payload:1})

0 comments on commit 53a09a6

Please sign in to comment.