I'm filtering an Observable
with the input of another Observable
- the input for the filtering comes from the user.
The filtering is done with the RxJS operator combineLatest
. Using this means that when subscribing to this stream, no values are emitted until there has been an emission from both source Observables - I'd like the created stream to emit on creation (without any filtering), before any user input takes place.
I think I should be using the startWith
operator so the stream has an emission on creation, but I can't work out how to seed this from an Observable. Using an Observable because data comes from Firebase and is handled with FirebaseListObservable
's.
Below is a pieced-together version of what I'm doing currently.
let tagInput = document.getElementById('tags');
let tagExclusionStream = Observable
.fromEvent(tagInput, 'input')
.map((e: any) => createsArrayFromInput(e.target.value));
let allTags: Observable<any[]> = getAllTags();
let filteredTags = allTags
.combineLatest(tagExclusionStream, (tags, tagExclusions) => {
return tags.filter((tag: any) => tagExclusions.indexOf(tag.$key) == -1)
});
// I want this to print out without needing the tagExclusionStream to emit first
filteredTags.subscribe(tags => console.log("Tags:", tags))
Please let me know if my approach here is completely off/there's a better way as I'm new to RxJS.