Skip to content

Instantly share code, notes, and snippets.

View TapaniAla's full-sized avatar

TapaniA TapaniAla

  • TaalVision Technologies Oy
  • Oulu, Finland
View GitHub Profile
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const addCounter = (list) => {
//both are OK:
//return list.concat([0]);
return [...list, 0];
};
const removeCounter = (list,index) => {
// not allowed
// list.splice(index, 1);
return [
const toggleTodo = (todo) => {
// not allowed
//todo.completed = !todo.completed;
//this OK
// return {
// id: todo.id,
// text: todo.text,
// completed: !todo.completed
// };
// note the last assign property wins!
const todos = (state=[], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{id: action.id,
text: action.text,
completed: false
}
];
const todos = (state=[], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{id: action.id,
text: action.text,
completed: false
}
];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
</head>
<body>
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
if(state.id !== action.id) {