我有以下减速器:
export function partnerReducer(state = PartnerState.getInitialState(), action: Actions): PartnerState {
console.log('state', state)
switch (action.type) {
case STORE_PARTNER:
return { ...state, partner: action.payload }
case RESET_PARTNER:
console.log('calling this')
return { ...state, partner: action.payload }
default:
return state
}
}
这是PartnerState
类
export default class PartnerState {
partner: Partner
static getInitialState() {
const partnerState = new PartnerState()
partnerState.partner = new Partner()
return partnerState
}
}
这是组件中的代码
this.store.select(getPartner).subscribe((partner: Partner) => {
let retrievedPartner = partner
console.log('retrievedPartner', retrievedPartner)
if (Util.isNull(retrievedPartner) || Util.isEmpty(retrievedPartner)) {
console.log('retrieved partner is null')
this.getPartner()
} else {
console.log('got a partner')
this.partner = retrievedPartner
this.getPartnerUsers()
}
})
}
this.getPartner()
调用服务并检索合作伙伴。成功时,合作伙伴会像this.store.dispatch(new StorePartnerAction(response))
但每当我在浏览器中刷新路径时,我都会收到此回复:
state
Object { partner: {} }
retrievedPartner
Object { }
retrieved partner is null
state
Object { partner: {} }
retrievedPartner
Object { ... partner object}
got a partner
页面重新加载的预期响应:
state
Object { partner: ...Partner Params }
retrievedPartner
Object { ... partner object}
got a partner