Register and share your invite link to earn from video plays and referrals.

Jacob Bartlett
@jacobtechtavern
By day: product engineer @meetgranola By night: Barkeep at Jacob's Tech Tavern 🍺
Joined December 2020
1.7K Following    5.9K Followers
The Repository pattern is an approach for implementing a Data Access Layer in your app. The core idea is to manage data access logic in a centralised location. LoadingState here is a simple wrapper enum that works like a souped-up Result type: the idle and loading cases let the API users know whether we are waiting for a value or not, as well as returning the success state with the desired values or any errors. We ask our API dependency to fetch some beer data over the network. If this works, we can then send the array of Beers to our publisher, which broadcasts the values wrapped in a .success state. Finally, we handle the unhappy path. Here, we're simply passing the error to the consumer of our interface to handle, again wrapped in a .failure state. The UI layer checks for these errors and handles them in a way that's helpful to the user.
Show more