javascript - How to use redux-observable and promise correctly? -
i using hello.js sign in.
hello('abc').login()
returns promise.
it did sign in successfully, because hello.js saved token in local storage.
however, code below not dispatch action sign_in_succeed
.
export const signinepic = (action$, store) => action$ .oftype(sign_in) .mergemap(action => observable .frompromise(hello('msft').login({ scope })) .map(response => ({ type: sign_in_succeed, payload: response.authresponse.access_token }) ) .catch(error => observable.of({ type: sign_in_failed, payload: error })) );
update: jay's pause on caught exceptions way helped me find error. code above has no issue. causes problem first try save token store after getting sign_in_succeed
. use token once app sign in fetch something. when fetch using token step runs before saving token in store step, causes issue won't dispatch sign_in_succeed
.
if make assumptions things missing in example (e.g. scope
, hello.js does, etc) works expected. here's example: https://jsbin.com/rasumo/edit?js,output
there must else wrong code isn't included here, unfortunately. how did confirm it's not dispatching sign_in_succeed
action? there errors in console? have tried enabling "pause on caught exceptions" in debugger see if you're maybe silently swallowing error somewhere preventing action reaching reducers?
another thing confirm promise returned hello('msft').login({ scope })
resolve. chain .then()
confirm this.
hope helps!
Comments
Post a Comment