https://github.com/rundfunk47/store
Implementation of the repository pattern in Swift, using generics.
https://github.com/rundfunk47/store
Last synced: 21 days 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 (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-05T13:48:09.000Z (over 2 years ago)
- Last Synced: 2025-06-23T15:07:52.535Z (22 days ago)
- Language: Swift
- Size: 58.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Store
[](https://swift.org)
[](https://apple.com)
[](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.