对于redux reducer步骤: 如果我只想更改initial_state的一个属性,该怎么办?例如:
class ModalVC: UIViewController, GADInterstitialDelegate
func interstitialWillDismissScreen(ad: GADInterstitial!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
此处我只想将const INITIAL_STATE = {
signInInfo: {
signin: false,
name: "",
email: "",
...
},
changePassword: {
status: false,
...
}
...
};
设置为signInInfo.signin
,目前,我知道的唯一方法是输入完整的" signInInfo"喜欢:
true
case SIGNIN_USER:
return { ...state, signInInfo: action.payload.data };
就像:
action.payload.data
另一个问题是,如果我想将{
signin: true,
name: "Qing",
email : ...
}
设置为signInInfo.signin
,同时还需要将false
从changePassword.status
更改为false
。
我该怎么办?任何人都可以给我一个提示吗?
答案 0 :(得分:3)
相当简单(两个问题):
case SIGNIN_USER: return {
...state,
signInInfo: {
...state.signInInfo,
signin: action.payload.signin
},
changePassword: {
...state.changePassword,
status: true
}
};