Skip to content

Commit

Permalink
Added more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
buckyroberts committed Jul 3, 2016
1 parent e93973e commit 2475b58
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
Boilerplate for a React / Redux build.

![](http://i.imgur.com/2PAD0kp.png)

## Containers vs. Components

Containers are very similar to components, the only difference is that components are aware of application state. If
part of your webpage is only used for displaying data (dumb) then make it a component. If you need it to be smart and
aware of the state (whenever data changes) in the application then make it a container.
56 changes: 20 additions & 36 deletions dev/js/reducers/users.js
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."
}
]
}

0 comments on commit 2475b58

Please sign in to comment.