Creating awesome by combining startWith
and EventEmitter
It’s quite easy to get lost in RxJS. There are plenty of operators to choose from and on my developer journey, I’ve discovered that it’s really easy to overlook an operator that might save you a headache or 2.
Following on from my previous article discussing flatMap vs. switchMap, in this article I’m going to cover startWith
.
The official definition from the RxJS documentation is:
Returns an Observable that emits the items you specify as arguments before it begins to emit items emitted by the source Observable.
The Problem
As usual, with programming, it’s too easy to get consumed by the “what” and not really the “why”, so we’ll start with a problem definition.
Given I have a seed value that queries for a list of sub values, how can I subscribe to a Refresh Event that updates the list even when the seed doesn’t change?
That might be confusing, so, broken down into another way:
- My support system shows a list of open tickets
path/to/tickets
- An operator selects a ticket
/path/to/tickets/:id
- All of the comments inside that ticket are displayed