javascript 终极版,101.js
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 终极版,101.js相关的知识,希望对你有一定的参考价值。
import { createStore } from 'redux';
// Action Generators
const incrementCount = ({ incrementBy = 1 } = {}) => ({
type: 'INCREMENT',
incrementBy
});
const decrementCount = ({ decrementBy = 1 } = {}) => ({
type: 'DECREMENT',
decrementBy
});
const setCount = ({ count }) => ({
type: 'SET',
count
});
const resetCount = () => ({
type: 'RESET'
});
// Reducers
// 1. Reducers are PURE functions
// 2. NEVER change state or action arguments, create new ones
const countReducer = (state = { count: 0 }, action) => {
switch (action.type) {
case 'INCREMENT':
return { count: state.count + action.incrementBy };
case 'DECREMENT':
return { count: state.count - action.decrementBy };
case 'SET':
return { count: action.count }
case 'RESET':
return { count: 0 };
default:
return state;
}
};
// Store
const store = createStore(countReducer);
// Create Subscriber
const unsubscribe = store.subscribe(() => {
console.log(store.getState());
});
// unsubscribe();
// Dispatch Events
store.dispatch(setCount({ count: 100 }));
store.dispatch(decrementCount());
store.dispatch(decrementCount({ decrementBy: 9 }));
store.dispatch(resetCount());
以上是关于javascript 终极版,101.js的主要内容,如果未能解决你的问题,请参考以下文章
javascript 终极版,counter.html
javascript 终极版,反应
javascript 终极版,sample.js
javascript 终极版
阿里正式发布《Java开发手册》终极版!
markdown 终极版