-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
完成了收藏store有关的redux,新建了三个常量,新建了一个action,新建了一个reducers
- Loading branch information
Showing
10 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as actionTypes from '~constants/store'; | ||
|
||
export function update(data) { | ||
return { | ||
type: actionTypes.STORE_UPDATE, | ||
data | ||
}; | ||
}; | ||
|
||
export function add(item) { | ||
return { | ||
type: actionTypes.STORE_ADD, | ||
data: item | ||
}; | ||
}; | ||
|
||
export function rm(item) { | ||
return { | ||
type: actionTypes.STORE_RM, | ||
data: item | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ export function update(data) { | |
type: actionTypes.USERINFO_UPDATE, | ||
data | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const STORE_UPDATE = 'STORE_UPDATE'; // 更新 | ||
export const STORE_ADD = 'STORE_ADD'; // 添加 | ||
export const STORE_RM = 'STORE_RM'; // 删除 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const USERINFO_UPDATE = 'userinfo_update'; | ||
export const USERINFO_UPDATE = 'USERINFO_UPDATE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
import userinfo from './userinfo'; | ||
import store from './store'; | ||
|
||
export default combineReducers({ | ||
userinfo | ||
userinfo, | ||
store | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as actionTypes from '../constants/store'; | ||
|
||
const initialState = []; | ||
|
||
export default function store(state = initialState, action) { | ||
switch (action.type) { | ||
case actionTypes.STORE_UPDATE: | ||
return action.data; | ||
case actionTypes.STORE_ADD: | ||
state.unshift(action.data); // 放在最前面 | ||
return state; | ||
case actionTypes.STORE_RM: | ||
const newState = state.filter(item => { | ||
return item.id !== action.data.id; | ||
}); | ||
console.log(newState) | ||
return newState; | ||
default: | ||
return state; | ||
} | ||
}; |