Sovran-Swift: Small, efficient, easy. State Management for Swift

Related tags

Utility Sovran-Swift
Overview

// add badges and stuff here

Sovran-Swift

Small, Efficient, Easy. State Management for Swift.

Sovran's goal is to be minimal, efficient, easy to implement and to make debugging state changes effortless.

While it is a rather opinionated library, we hope that you'll find said opinions to be with good reason. While it is somewhat similar to things like Redux and Flux there are some natural differences when applied to Swift.

We don't like large state structures

Large state structures just aren't terribly useful. Subscribers typically only care about a small subset of the data contained within. We have opted to allow multiple state structures to be supplied and work in unison. This has the benefit of subscribers to be given just the parts of the state that they are interested in. It's highly recommended that state structures only contain properties that relate to one another in some obvious way.

By using structs to define state objects, we benefit from the natural copy mechanism within Swift to make sure no direct access to state is given to subscribers.

We don't like artificial constraints

We've been very careful to not dictate how you write your code. If you want one state structure to subscribe to another unrelated state, we assume you have a good reason. If you want a single giant state structure, while it's not our first choice of solutions, you can do that if you need to. If you need to be unconventional, do it. Everything has a time and place.

Types should be explicit, but inferred where possible

You'll notice that when using Sovran, it's actually the closure input that defines the type of state that a given subscription is intended to work against. This allows us to avoid having developers supply the type twice.

Example:

store.subscribe(self) { (state: MyState) in
    // MyState was updated, react to it in some way.
    print(state)
}

In the example above, MyState is defining the generic type needed by the subscribe call.

We want it to be very debuggable

It is very common for bugs to occur in code. This library is architected such that most anywhere within the library as well as your own code, the stack trace shows the exact point a state change was initiated and all points in between. We didn't want to replicate the frustration that's common in other similar systems, such as NotificationCenter, where hours are spent trying to figure out where/why a notification was sent so that a bug can be addressed.

// Insert screenshot of Xcode stack trace showing this.

Getting Started

// TODO

Contributing

Why not Combine?

  • Combine is closed-source and only available on Apple platforms.
  • Combine uses compiler-magic to do its job.
  • We need state wherever Swift can be used (Android, Linux, etc)
  • Combine is designed around and for Apple's other tools, SwiftUI, etc.

License

MIT License

Copyright (c) 2021 Segment

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
Swift Date() made easy

Swift-Date-Extensions Swift Date() made easy! // Will return the wekkday in a st

Handling dimensional numbers with physical units in Swift made easy.

Dimensional arithmetics in Swift This package provides an easy and natural way of dealing with physical sizes. Performing complex arithmetics or unit

Testable Combine Publishers - An easy, declarative way to unit test Combine Publishers in Swift
Testable Combine Publishers - An easy, declarative way to unit test Combine Publishers in Swift

Testable Combine Publishers An easy, declarative way to unit test Combine Publishers in Swift About Combine Publishers are notoriously verbose to unit

SwiftRegressor - A linear regression tool that’s flexible and easy to use

SwiftRegressor - A linear regression tool that’s flexible and easy to use

Easy CBOR encoding and decoding for iOS, macOS, tvOS and watchOS.

CBORCoding CBORCoding is a lightweight framework containing a coder pair for encoding and decoding Codable conforming types to and from CBOR document

An application focused on managing men's haircuts. It has never been so easy to keep the cut on time
An application focused on managing men's haircuts. It has never been so easy to keep the cut on time

An application focused on managing men's haircuts. It has never been so easy to keep the cut on time

BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

Comments
  • minor changes

    minor changes

    • Added release automation script.
    • Added Version.swift.
    • Removed Codable conformance for Store since it's unnecessary.
    • Added proper CI setup.
    • Restricted subscription owner to Subscriber instead of Any.

    Replaces PR #2

    opened by bsneed 0
  • Minor Changes

    Minor Changes

    • Added release automation script.
    • Added Version.swift.
    • Removed Codable conformance for Store since it's unnecessary.
    • Added proper CI setup.
    • Restricted subscription owner to Subscriber instead of Any.
    opened by bsneed 0
Releases(1.0.3)
Owner
Segment
Segment
A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

李阳 4 Dec 29, 2022
A simple, but efficient CSV Parser, written in Swift.

CSV CSV.swift is a powerful swift library for parsing CSV files that supports reading as [String], [String: String] and Decodable, without sacrificing

Ben Koska 4 Nov 28, 2022
SwiftRedux is a Swift implementation of the Redux state container

SwiftRedux is a Swift implementation of the Redux state container. It relies on the same concepts and provides familiar Hooks through property wrappers.

Lucas Lima 8 Feb 1, 2022
🚀Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

??Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

Cheng Zhang 18 Mar 9, 2022
Small app that checks focus status under macOS 12

infocus What Small app for Mac Admins that checks focus status under macOS 11 and 12 and can be used to add Do Not Disturb support to management scrip

Bart Reardon 12 Nov 8, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
🗃 Powerful and easy to use Swift Query Builder for Vapor 3.

⚠️ This lib is DEPRECATED ⚠️ please use SwifQL with Bridges Quick Intro struct PublicUser: Codable { var name: String var petName: String

iMike 145 Sep 10, 2022
RandomKit is a Swift framework that makes random data generation simple and easy.

RandomKit is a Swift framework that makes random data generation simple and easy. Build Status Installation Compatibility Swift Package Manager CocoaP

Nikolai Vazquez 1.5k Dec 29, 2022
CocoAttributedStringBuilder: Elegant and Easy AttributedStringBuilder in Swift

CocoAttributedStringBuilder: Elegant and Easy AttributedStringBuilder in Swift Features Requirements Installation SampleProjects Usage Contributors Li

Kiarash Vosough 10 Sep 5, 2022
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Easy way to detect device environment: Device model and version Screen resolution Interface orientation iOS version Battery state Environment Helps to

Anatoliy Voropay 582 Dec 25, 2022