Created
December 2, 2019 21:24
-
-
Save raydot/715f2db7028c89237e7966f5de2a7e6b to your computer and use it in GitHub Desktop.
Redux Tutorial Video 10 // source https://jsbin.com/carezix
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Video 10"> | |
<meta charset="utf-8"> | |
<title>Redux Tutorial</title> | |
<script src="https://wzrd.in/standalone/expect@latest"></script> | |
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const toggleTodo = (todo) => { | |
//ANTIPATTERN: Mutation | |
//todo.completed = !todo.completed; | |
//return todo; | |
// This works, but is hard to maintain | |
//return { | |
// id: todo.id, | |
// text: todo.text, | |
// completed: !todo.completed | |
//} | |
// let's use Object.assign! | |
} | |
const testToggleTodo = () => { | |
const todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
} | |
const todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
} | |
deepFreeze(todoBefore); | |
expect( | |
toggleTodo(todoBefore) | |
).toEqual(todoAfter) | |
} | |
testToggleTodo() | |
console.log('Everything shipshape!') | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const toggleTodo = (todo) => { | |
//ANTIPATTERN: Mutation | |
//todo.completed = !todo.completed; | |
//return todo; | |
// This works, but is hard to maintain | |
//return { | |
// id: todo.id, | |
// text: todo.text, | |
// completed: !todo.completed | |
//} | |
// let's use Object.assign! | |
} | |
const testToggleTodo = () => { | |
const todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
} | |
const todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
} | |
deepFreeze(todoBefore); | |
expect( | |
toggleTodo(todoBefore) | |
).toEqual(todoAfter) | |
} | |
testToggleTodo() | |
console.log('Everything shipshape!')</script></body> | |
</html> |
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
const toggleTodo = (todo) => { | |
//ANTIPATTERN: Mutation | |
//todo.completed = !todo.completed; | |
//return todo; | |
// This works, but is hard to maintain | |
//return { | |
// id: todo.id, | |
// text: todo.text, | |
// completed: !todo.completed | |
//} | |
// let's use Object.assign! | |
} | |
const testToggleTodo = () => { | |
const todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
} | |
const todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
} | |
deepFreeze(todoBefore); | |
expect( | |
toggleTodo(todoBefore) | |
).toEqual(todoAfter) | |
} | |
testToggleTodo() | |
console.log('Everything shipshape!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment