Reputation: 13923
I'm facing a bug(?) when using ngrx.store and states.
After I dispach for new state and the reducer returns the new state nothing heppends . The subscribe doesn't get any error massages. If I remove switchMap, The code works and the subscriber get the values he shoud get.
I minimized my code as little as I could:
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);
}
);
}
My reducer:
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;
}
};
I did import switchMap as: "import 'rxjs/add/operator/switchMap';"
Upvotes: 0
Views: 2310
Reputation: 555
SwitchMap is a rxjs operator and therefor this if it were a bug would most likely not be a ngrx/store bug.
https://plnkr.co/edit/0Ul8S0VlRwuBUAOuYDKG?p=preview
this.userList = this.userListService.userList.switchMapTo(Observable.from([[new User(1, "Mr. Grant")]]));
I'm using a old plunker I already had set from another example but if you look in the component I added a switchMapTo(similar to a switchMap but it just doesn't pass in the value of the original Observable to the function). Everything switches over to the new Observable fine. I'm not sure of the rest of your code's setup but hopefully looking over this will give you some ideas of what might be wrong in your code.
Based off the code you've posted I honestly don't see why it wouldn't work. The error may lay somewhere else in your app or setup.
Upvotes: 1