I'm using third party library which give promises, but i need to wrap it to Observable in ngrx effect. The idea is to dispatch new action when app is initialized successfully. But i need to dispatch the data when the promise is resolved.
classOne.promise().then(result =>
nested.OnemorePromise(result).then(result2 =>
//(result2) dispatch new action here (result2)
)
);
I created something like this:
@Effect()
initializeValue$: Observable<Action> = this.actions$.pipe(
ofAction(AppInitializeAction),
map(action => {
classOne.promise().then(result =>
nested.OnemorePromise(result).then(result2 =>
this.store.dispatch(new Action(result2))
// ideally just - return new Action(result2)
)
);
})
upd:
@Effect()
initializeValue$: Observable<Action> = this.actions$.pipe(
ofAction(AppInitializeAction),
map(action => {
return from(classOne.promise()).map(result => {
console.log(result)
})
})
);
map is not a function.
You can use from in Rxjs >= 6:
import { from } from 'rxjs';
map(action => {
from(classOne.promise()).map(result ...
fromPromise in Rxjs <= 5:
import { fromPromise } from 'rxjs/observable/fromPromise';
map(action => {
fromPromise(classOne.promise()).map(result ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With