Skip to content

Implementation of the repository pattern in Swift, using generics.

License

Notifications You must be signed in to change notification settings

rundfunk47/store

Repository files navigation

Store

Language Platform 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.

About

Implementation of the repository pattern in Swift, using generics.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages