Skip to content

Instantly share code, notes, and snippets.

@raydot
Created December 2, 2019 21:24
Show Gist options
  • Save raydot/715f2db7028c89237e7966f5de2a7e6b to your computer and use it in GitHub Desktop.
Save raydot/715f2db7028c89237e7966f5de2a7e6b to your computer and use it in GitHub Desktop.
Redux Tutorial Video 10 // source https://jsbin.com/carezix
<!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>
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