I have an Apollo query that I pipe through a map operator to emit objects. For example, {name: "doron", color: "red"}.
query$ = this.apollo.watchQuery(query)
I want to split it into 2 observables - name$ and color$ so that name$ emits the name values and color$ emits the color values.
What we do today is this:
name$ = new Subject();
color$ = new Subject();
query$.valueChanges.subscribe(p => {
name$.next(p.name);
color$.next(p.color);
})
This is not ideal because we need to manually unsubscribe. Also, it subscribes to the query before any of the "child" observables is being subscribed to.
How can I do this without subscribing to the query?