2017-06-21 34 views
0

我有這樣終極版,觀測mergeMap W /兩路輸出

/** 
* Request a new account from the API 
*/ 
export function signupApiRequest(action$: Observable, store: Store) { 
    return action$.ofType(SIGNUP) 
    .map(action => [ action, store.getState().accounts.signup ]) 
    .mergeMap(([ action, signup ]) => 
     sendCommand('/api/accounts/signup', { 
      name: signup.name, 
      email: signup.email 
     }) 
     .map(response => [ response, signup.email ]) 
    ) 
    .mergeMap(([ response, email ]) => { 
     switch (response.status) { 
     case 409: 
      return [existingUser(email)]; 

     case 201: 
      const succ = { type: successOf(SIGNUP) }, 
       user = mapTokenToUser(response.body.data), 
       created = userCreated(user); 
      console.log('signup success', [succ, created]); 
      return [succ, created]; 

     default: 
      throw new Error(`Unknown response code ${response.code}`); 
     } 
    }); 
} 

史詩報名時,「註冊成功」打印和動作都被記錄,他們應該。

但是,只有第一個動作從史詩輸出。 Redux actions for realz

爲什麼和我做錯了什麼?

更改數組中的順序使得輸出另一個值。

+0

https://開頭的github .COM /終極版可觀測/ Redux的可觀測/問題/ 263 – Henrik

回答

1

我們發現這似乎是RxJS本身的一個錯誤,從5.1.0開始。你的減速器中有一個例外,但它正在被RxJS無聲無息地吞噬。

https://github.com/redux-observable/redux-observable/issues/263#issuecomment-310180351

它是如何與終極版/終極版,可觀察到的交互是有點複雜,但最終沒有關係的,因爲這可以被複制:

https://jsbin.com/dukixu/edit?html,js,output

const input$ = new Rx.Subject(); 

input$ 
    .mergeMap(() => Rx.Observable.of(1, 2)) 
    .subscribe(d => { 
    throw new Error('some error'); 
    }); 

input$.next();