Created
July 3, 2017 16:21
-
-
Save giopunt/864c0ab3574e9c301c6c234f34a7039c to your computer and use it in GitHub Desktop.
BASIC REDUX IMPMENTATION #2 // source https://jsbin.com/xuriren
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>BASIC REDUX IMPMENTATION #2</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.js"></script> | |
<script src="https://unpkg.com/expect/umd/expect.min.js"></script> | |
</head> | |
<body> | |
<h1>BASIC REDUX IMPMENTATION #2</h1> | |
<p>DevTools (F12) -> see the magic</p> | |
<script id="jsbin-javascript"> | |
const counter = (state = 0, action) => { | |
switch(action.type){ | |
case "INCREMENT": | |
return state + 1; | |
case "DECREMENT": | |
return state - 1; | |
default: | |
return state; | |
} | |
return state; | |
} | |
const { createStore } = Redux; | |
const store = createStore(counter); | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(2) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(0) | |
console.log("ALL TEST PASSED !!") | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const counter = (state = 0, action) => { | |
switch(action.type){ | |
case "INCREMENT": | |
return state + 1; | |
case "DECREMENT": | |
return state - 1; | |
default: | |
return state; | |
} | |
return state; | |
} | |
const { createStore } = Redux; | |
const store = createStore(counter); | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(2) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(0) | |
console.log("ALL TEST PASSED !!")</script></body> | |
</html> |
This file contains hidden or 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
const counter = (state = 0, action) => { | |
switch(action.type){ | |
case "INCREMENT": | |
return state + 1; | |
case "DECREMENT": | |
return state - 1; | |
default: | |
return state; | |
} | |
return state; | |
} | |
const { createStore } = Redux; | |
const store = createStore(counter); | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "INCREMENT" }); | |
expect( store.getState() ).toEqual(2) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(1) | |
store.dispatch({ type: "DECREMENT" }); | |
expect( store.getState() ).toEqual(0) | |
console.log("ALL TEST PASSED !!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment