Created
March 30, 2017 00:00
-
-
Save razchiriac/0c16d2c65e0926e1ef26bbdccea07abf to your computer and use it in GitHub Desktop.
Redux Todo Toggle - Immutable // source https://jsbin.com/befipuy
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 charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Redux Todo Toggle - Immutable</title> | |
<script src="https://unpkg.com/redux@3.6.0/dist/redux.min.js"></script> | |
<script src="https://unpkg.com/expect/umd/expect.min.js"></script> | |
</head> | |
<body> | |
<script src="https://fb.me/react-with-addons-15.1.0.js"></script> | |
<script src="https://fb.me/react-dom-15.1.0.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
var toggleTodo = function toggleTodo(todo) { | |
return _extends({}, todo, { | |
completed: !todo.completed | |
}); | |
}; | |
var testToggleTodo = function testToggleTodo() { | |
var todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
}; | |
var todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
}; | |
expect(toggleTodo(todoBefore)).toEqual(todoAfter); | |
}; | |
testToggleTodo(); | |
console.log('All tests passed!'); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const toggleTodo = (todo) => { | |
return { | |
...todo, | |
completed: !todo.completed | |
}; | |
}; | |
const testToggleTodo = () => { | |
const todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
}; | |
const todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
}; | |
expect(toggleTodo(todoBefore)).toEqual(todoAfter); | |
}; | |
testToggleTodo(); | |
console.log('All tests passed!');</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
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
var toggleTodo = function toggleTodo(todo) { | |
return _extends({}, todo, { | |
completed: !todo.completed | |
}); | |
}; | |
var testToggleTodo = function testToggleTodo() { | |
var todoBefore = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: false | |
}; | |
var todoAfter = { | |
id: 0, | |
text: 'Learn Redux', | |
completed: true | |
}; | |
expect(toggleTodo(todoBefore)).toEqual(todoAfter); | |
}; | |
testToggleTodo(); | |
console.log('All tests passed!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment