-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e93973e
commit 2475b58
Showing
2 changed files
with
26 additions
and
36 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,23 @@ | ||
/* | ||
* Reducers take in the current state of app, action being performed, and return new state (new object) | ||
* - must always return something (even empty state object if needed) | ||
* The users reducer will always return an array of users no matter what | ||
* You need to return something, so if there are no users then just return an empty array | ||
* */ | ||
|
||
// Individual user | ||
const user = (state = {}, action) => { | ||
switch (action.type) { | ||
case 'ADD_USER': | ||
return { | ||
id: action.id, | ||
first: action.first, | ||
last: action.last, | ||
age: action.age, | ||
description: action.description | ||
}; | ||
default: | ||
return state | ||
} | ||
}; | ||
|
||
// All users | ||
const users = (state = [], action) => { | ||
switch (action.type) { | ||
case 'ADD_USER': | ||
return [ | ||
...state, | ||
user(undefined, action) | ||
]; | ||
case 'TOGGLE_TODO': | ||
return state.map(t => | ||
user(t, action) | ||
); | ||
default: | ||
return state | ||
} | ||
}; | ||
|
||
export default users | ||
export default function () { | ||
return [ | ||
{ | ||
id: 1, | ||
first: "Bucky", | ||
last: "Roberts", | ||
age: 71, | ||
description: "Bucky is a React developer and YouTuber" | ||
}, | ||
{ | ||
id: 2, | ||
first: "Joby", | ||
last: "Wasilenko", | ||
age: 27, | ||
description: "Joby loves the Packers, cheese, and turtles." | ||
} | ||
] | ||
} |