|
@@ -5,19 +5,46 @@ import countSlice from './slices/count.js';
|
|
|
import newSlice from './slices/newCount.js';
|
|
|
// 2.创建store
|
|
|
|
|
|
+function counterReducer(state={value:0},action) {
|
|
|
+ switch (action.type) {
|
|
|
+ case 'counter/addValue':
|
|
|
+ return {value:state.value + 1};
|
|
|
+ case 'counter/reduceValue':
|
|
|
+ return {value:state.value - 1};
|
|
|
+ case 'counter/newValue':
|
|
|
+ return {value:state.value + action.payload};
|
|
|
+ default:
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function addMain() {
|
|
|
+ return {
|
|
|
+ type:'counter/addValue'
|
|
|
+ }
|
|
|
+}
|
|
|
+export function reduceMain() {
|
|
|
+ return {
|
|
|
+ type:'counter/reduceValue'
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function newMain(val) {
|
|
|
+ return {
|
|
|
+ type:'counter/newValue',
|
|
|
+ payload: val
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
const store = configureStore({
|
|
|
reducer:{
|
|
|
userSlice,
|
|
|
countSlice,
|
|
|
- newSlice
|
|
|
+ newSlice,
|
|
|
+ counterReducer
|
|
|
}
|
|
|
})
|
|
|
-export function addCount(val) {
|
|
|
- return {
|
|
|
- type:'count/add',
|
|
|
- payload:val
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
// 3.抛出store
|
|
|
export default store;
|