I am using using RxJS (version 6+) to switchMap to another observable which needs to be emitting one value to start the pipe(line).
The current solution is using:
const saveAction$ = new Observable(observer => {
observer.next();
}).pipe(switchMap(() => this.saveAction()))
which creates an observable that immediately emits.
The this.saveAction() returns an Observable<void> which contains some synchronous code and a return of a call to the HttpClient.
The saveAction$ is being saved in a redux store which will be called when another component dispatches the handleSaveChanges.
Another option would be using of(true), but the true has no value here, because it would not be used.
Using a Subject would be another option, but the overhead of a subject is not needed, because I need it to only emit once and then complete.
There is an EMPTY (https://rxjs-dev.firebaseapp.com/api/index/const/EMPTY) constant that gives an observable that completes, but never emits. It would be much nicer if there was something like ONCE, instead of using the constructor.
Are there other ways, which are cleaner, to solve this problem?
saveChanges$ = this.reduxStore.events$.pipe(filter(e => e.type === 'handleSaveAction'), switchMapTo(this.saveAction))- BizzyBob