当使用ngrx.store和states时,我正面临一个bug(?) .
在我调度新状态后,reducer返回新状态 nothing heppends . 订阅不会得到任何错误按摩 . If I remove switchMap, The code works 并且订户获得他应得的 Value .
我尽量减少了我的代码:
public a$:Observable<any>;
constructor(private _userService:UserService, private _store:Store<any>)
{
this.a$=this._store
.select(state=>state)
.switchMap(state=>
{
return Observable.from(["1"]); //for simplicity.
});
this.a$.subscribe(
something=>{
console.log(something);
},
error=>{
console.log(error);
}
);
}
我的减速机:
export const connectedUserReducer = (state = initialState, action:Action) =>
{
if(action==null || action.type==null)
return state;
switch (action.type) {
case updateConnectedUser:
return Object.assign({},state); <<<-- It comes here and then nothing heppends.<<--
default:
return state;
}
};
我把switchMap导入为:“import'rxjs / add / operator / switchMap';”
1 回答
SwitchMap是一个rxjs运算符,因此如果它是一个bug很可能不是一个ngrx / store bug .
https://plnkr.co/edit/0Ul8S0VlRwuBUAOuYDKG?p=preview
我正在使用一个我从另一个例子中设置的旧plunker但是如果你查看组件我添加了一个switchMapTo(类似于switchMap但它只是没有将原始Observable的值传递给该函数) . 一切都切换到新的Observable罚款 . 我不确定你的其余代码的设置,但希望看一下这会给你一些关于你的代码可能出错的一些想法 .
根据您发布的代码,我老实说不明白为什么它不起作用 . 该错误可能位于您的应用或设置中的其他位置 .