javascript 终极版
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 终极版相关的知识,希望对你有一定的参考价值。
import { createStore, combineReducers } from 'redux';
import uuid from 'uuid';
// Action Generators
// ADD_EXPENSE
const addExpense = ({ description = '', note ='', amount = 0, createdAt = 0 } = {}) => ({
type: 'ADD_EXPENSE',
expense: {
id: uuid(),
description,
note,
amount,
createdAt
}
});
// REMOVE_EXPENSE
const removeExpense = ({ id } = {}) => ({
type: 'REMOVE_EXPENSE',
id
});
// Reducers
// Expenses Reducer
const expensesReducerDefaultState = [];
const expensesReducer = (state = expensesReducerDefaultState, action) => {
switch (action.type) {
case 'ADD_EXPENSE':
return [...state, action.expense];
case 'REMOVE_EXPENSE':
return state.filter(({ id }) => id !== action.id);
default:
return state;
}
};
// Filters Reducer
const filtersReducerDefaultState = {
text: '',
sortBy: 'date',
startDate: undefined,
endDate: undefined
}
const filtersReducer = (state = filtersReducerDefaultState, action) => {
switch (action.type) {
default:
return state;
}
}
// Store Creation
const store = createStore(
combineReducers({
expenses: expensesReducer,
filters: filtersReducer
})
);
// Subscriber
store.subscribe(() => {
console.log(store.getState());
});
const expenseOne = store.dispatch(addExpense({ description: 'rent', amount: 100 }));
const expenseTwo = store.dispatch(addExpense({ description: 'coffee', amount: 300 }));
store.dispatch(removeExpense({ id: expenseOne.expense.id }));
// ------------------------
// const demoState = {
// expenses: [{
// id: 'asasasasas',
// description: 'January Rent',
// note: 'This was the final payment for that address',
// amount: 54500,
// createdAt: 0
// }],
// filters: {
// text: 'rent',
// sortBy: 'amount', // date or amount
// startDate: undefined,
// endDate: undefined
// }
// };
以上是关于javascript 终极版的主要内容,如果未能解决你的问题,请参考以下文章
javascript 终极版,反应
javascript 终极版,sample.js
javascript 终极版,101.js
javascript 终极版
阿里正式发布《Java开发手册》终极版!
markdown 终极版