Skip to content

Instantly share code, notes, and snippets.

View z2015's full-sized avatar
🎯
Focusing

William Zhou z2015

🎯
Focusing
View GitHub Profile
@z2015
z2015 / redux.js
Created May 2, 2016 02:45
Redux: Reducer Composition with Objects
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 02:45
Redux: Reducer Composition with combineReducers()
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 02:45
Redux: Implementing combineReducers() from Scratch
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 03:16
Redux: React Todo List Example (Adding a Todo)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 03:25
Redux: React Todo List Example (Toggling a Todo)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 07:21
Redux: React Todo List Example (Filtering Todos)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 07:35
Redux: Extracting Presentational Components (Todo, TodoList)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 08:05
Redux: Extracting Presentational Components (AddTodo, Footer, FilterLink)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 08:29
Redux: Extracting Container Components (FilterLink)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':
@z2015
z2015 / redux.js
Created May 2, 2016 08:54
Redux: Extracting Container Components (VisibleTodoList, AddTodo)
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':