註冊並分享邀請連結,可獲得影片播放與邀請獎勵。

Jacob Bartlett
@jacobtechtavern
By day: product engineer @meetgranola By night: Barkeep at Jacob's Tech Tavern 🍺
加入 December 2020
1.7K 正在關注    5.9K 粉絲
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.
顯示更多