Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rundfunk47/store
Implementation of the repository pattern in Swift, using generics.
https://github.com/rundfunk47/store
Last synced: about 2 months ago
JSON representation
Implementation of the repository pattern in Swift, using generics.
- Host: GitHub
- URL: https://github.com/rundfunk47/store
- Owner: rundfunk47
- License: mit
- Created: 2022-08-28T17:29:55.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-05T13:48:09.000Z (almost 2 years ago)
- Last Synced: 2023-06-16T16:01:04.061Z (over 1 year ago)
- Language: Swift
- Size: 58.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Store
[![Language](https://img.shields.io/static/v1.svg?label=language&message=Swift%205&color=FA7343&logo=swift&style=flat-square)](https://swift.org)
[![Platform](https://img.shields.io/static/v1.svg?label=platforms&message=iOS%20|%20tvOS%20|%20watchOS%20|%20macOS&logo=apple&style=flat-square)](https://apple.com)
[![License](https://img.shields.io/cocoapods/l/Crossroad.svg?style=flat-square)](https://github.com/rundfunk47/store/blob/master/LICENSE)Simple, powerful and elegant implementation of the repository pattern, using generics.
# Why? 🤔
There are a couple of ways to implement the Repository-pattern in Swift. Creating custom classes for each one of your stores will lead to a lot of boiler-plate. Also, you'd probably need to implement support for Combine, `async`-functions to fetch the data etc.
# What? 🤷🏽♂️
In order to remedy this, `Store` provides two generic protocols `ReadStore` and `Store` that can be used. It also comes with some implementations out-of-the-box:
* `AsyncStore` for feching data asynchronously.
* `MemoryStore` for when you already have the data on hand.Stores have a state (loading, error or loaded) and also have a `fetch()`-function to do the initial fetching. Stores can be chained using the `chainWith()`-function. This means, you can use the output from the first fetch as input for a second fetch. Perfect when you for instance get an ID from a network call and need to do another call to fetch the entity. You can also do parallel fetching (using the `parallel()`-function). If any of these calls fail, the store state will be errored. The stores can be mapped, unwrapped etc.