u/AFulhamImmigrant

RxJS: are you supposed to use tap to set state in the service, when data is retrieved from an API?

What is the best practice when loading data from an API that you want to set in a service? I see two approaches:

public load()
{
    return this.api.listItems().pipe(
        tap((items) => {
            this.items.set(items);
        }),
        switchMap(() => of(void 0)),
    );
}

or

public load()
{
    return this.api.listItems();
}

public set(items: Item[])
{
    this.items.set(items);
}

The first feels easier to read but feels like I am hacking tap in a way it shouldn't be used?

The second seems more correct but feels like I have extra code?

reddit.com
u/AFulhamImmigrant — 1 day ago

You’re not laughing now, are you?

Anyone here who said the new era under RTD was trash was instantly downvoted, implied to be a bigot or any number of things.

The reality is that unlike the brainwashed cult here, we were a lot more in tune with the public than any of you.

reddit.com
u/AFulhamImmigrant — 2 months ago