Skip to content

bwoods/Architecture

Repository files navigation

A Composable Architecture

The Swift Composable Architecture library improves upon previous Redux-inspired patterns by leveraging the capabilities of the Swift language to achieve better Type Safety, Ergonomics and Performance.

This crate attempts to do the same to the Swift Composable Architecture itself by further leveraging the capabilities of the Rust language and ecosystem.

What is the Swift Composable Architecture?

The Composable Architecture (TCA, for short) is a library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind. It can be used in SwiftUI, UIKit, and more, and on any Apple platform (iOS, macOS, tvOS, and watchOS).

Learn More

The Composable Architecture was designed over the course of many episodes on Point•Free, a video series exploring functional programming and the Swift language, hosted by Brandon Williams and Stephen Celis.

The API has diverged to better reflect the different strengths (and weaknesses) of Rust and Swift, but the core ideals are the same.

  • State management

    Using States and Reducers to manage Rust’s restrictions on Variables and Mutability

  • Composition

  • Side effects

  • Testing

  • Ergonomics

License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0)

See LICENSE-APACHE and LICENSE-MIT for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Why use Composable?

A composable architecture is based around…

Note

If you have already used another unidirectional data flow architecture for application state management, the main take-away is that the State-Reducer pattern is a great fit to Rust’s restrictions on Variables and Mutability:

  • Rust requires mutable references to be unique
  • State mutations may only happen within a Reducer

As for this crate specifically. Features include:

  • Small

    The core functionality is around 3000 lines of code and has minimal dependancies.1

  • Fast

    Store::send takes less than 20 nanoseconds.
    Effects::actions are 5–10× faster.

  • Reliable

    No unsafe code.

Furthermore, the optional async handling is done without dependence on a runtime. A Store runs its Reducer entirely within a single thread. At the same time, Effects make it easy for an application to run code, concurrently or in parallel, that feeds its results back into the appropriate Reducer.

Usage

To use Composable, place the following line under the [dependencies] section in your Cargo.toml:

composable = { version = "0.7", git = "https://github.com/bwoods/Architecture.git" }

Other crates in the workspace

  • composable-dependencies supplies scoped/overrideable dependancies.
  • composable-views implements immediate-mode user interface elements that interface directly with Reducer Actions.
    • The examples crate within the workspace serves to both drive development and document usage of composable-views.
    • Note that composable_views is under heavy development, and changes to it are not considered a semver breaking change.

Footnotes

  1. As counted with tokei composable-architecture composable-dependencies --exclude benches.

About

Heavily inspired by Point•Free’s Swift Composable Architecture (aka The Composable Architecture)

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.md
MIT
LICENSE-MIT.md

Stars

Watchers

Forks

Contributors