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 / delete.sh
Created May 2, 2016 02:40
windows删除文件路径太长问题
文/guog(簡書作者)
原文鏈接:http://www.jianshu.com/p/95a269951a1b#
著作權歸作者所有,轉載請聯繫作者獲得授權,並標註“簡書作者”。
robocopy empty_dir will_delete_dir /purge
@z2015
z2015 / redux.js
Created May 2, 2016 02:41
Redux: Writing a Counter Reducer with Tests
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
@z2015
z2015 / redux.js
Created May 2, 2016 02:41
Redux: Store Methods: getState(), dispatch(), and subscribe()
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
@z2015
z2015 / redux.js
Created May 2, 2016 02:42
Redux: Implementing Store from Scratch
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
@z2015
z2015 / redux.js
Created May 2, 2016 02:43
Redux: React Counter Example
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
@z2015
z2015 / redux.js
Created May 2, 2016 02:43
Redux: Avoiding Array Mutations with concat(), slice(), and …spread
const addCounter = (list) => {
return [...list,0]
};
const removeCounter = (list, index) => {
return [
...list.slice(0, index),
...list.slice(index + 1)
];
};
@z2015
z2015 / redux.js
Created May 2, 2016 02:43
Redux: Avoiding Object Mutations with Object.assign() and …spread
const toggleTodo = (todo) => {
return {
...todo,
completed: !todo.completed
}
};
const testToggleTodo =()=> {
const todoBefore = {
id: 0,
@z2015
z2015 / redux.js
Created May 2, 2016 02:44
Redux: Writing a Todo List Reducer (Adding a Todo)
const todos = (state=[], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{
id: action.id,
text: action.text,
completed: false
}
@z2015
z2015 / redux.js
Created May 2, 2016 02:44
Redux: Writing a Todo List Reducer (Toggling a Todo)
const todos = (state=[], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{
id: action.id,
text: action.text,
completed: false
}
@z2015
z2015 / redux.js
Created May 2, 2016 02:44
Redux: Reducer Composition with Arrays
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
};
case 'TOGGLE_TODO':