I'm quite happy with your choice to create an Observable out of fromEvent
(be advised, the syntax you're showing signals and older (deprecated) version of RxJS, what version are you running? I will be using the latest version for my examples)
I think for your first question, you will want startWith()
.
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/startWith.ts
You'll use it like this:
fromEvent(this.editButton.nativeElement, 'click').pipe(
map(() => true),
startWith(false)
)
The second question is a bit more complicated, as a fromEvent()
Observable
does not complete
by default. This gives you a couple of options and it would heavily depend on your usecase.
The operators that come to mind:
take(x)
where x is a number of values to accept. If this is the first value, first()
works as well.
debounceTime(ms)
, which buffers all inputs and only emits after the debounce miliseconds has passed. You could add a take(1)
after that in combination to make it complete after.
Perhaps if you could expand on your use case, we could help you determine which operators or combination of these would help.