Sharing Observables: Preventing Identical Http Callsby@msarica
404 reads
404 reads

Sharing Observables: Preventing Identical Http Calls

by Mehmet2mJanuary 27th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Share is an rxjs operator that you can easily implement using. It prevents multiple identical requests in the Network tab. The result is 6 identical API calls in a project that has multiple components that need the same resource. An easy solution is to share observables. You can create a variable to keep a reference to the ongoing request. Make a request and share it so that this can become a multicast observable. Also make sure to remove the reference once we get a response from the request. This will not cache the value.

Company Mentioned

Mention Thumbnail
featured image - Sharing Observables: Preventing Identical Http Calls
Mehmet HackerNoon profile picture
Mehmet

Mehmet

@msarica

msarica.com

About @msarica
LEARN MORE ABOUT @MSARICA'S
EXPERTISE AND PLACE ON THE INTERNET.

Share Your Thoughts

About Author

Mehmet HackerNoon profile picture
Mehmet@msarica
msarica.com

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
L O A D I N G
. . . comments & more!