forked from learncodeacademy/react-js-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tutorial learncodeacademy#3 was followed
- Loading branch information
Nimmi Weeraddana
authored and
Nimmi Weeraddana
committed
Mar 13, 2017
1 parent
5c1a89a
commit 53a09a6
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |