Sharing Observables: Preventing Identical Http Calls

Written by msarica | Published 2020/01/27
Tech Story Tags: rxjs | angular | ionic | typescript | programming | javascript | web-components | angular-development

TLDR 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.via the TL;DR App

no story

Written by msarica | msarica.com
Published by HackerNoon on 2020/01/27