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).
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.
You can watch all of the episodes here, as well as a dedicated, multipart tour of the architecture from scratch: part 1, part 2, part 3 and part 4.
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
State
s andReducer
s to manage Rust’s restrictions on Variables and Mutability… -
Composition
-
Side effects
-
Testing
-
Ergonomics
Distributed under the terms of both the MIT license and the Apache License (Version 2.0)
See LICENSE-APACHE and LICENSE-MIT for details.
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.
A composable architecture is based around…
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 under 2000 lines of code and has minimal dependancies.1
-
Fast
Store::send
takes less than 20 nanoseconds.
Effects::action
s 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
.
To use Composable, place the following line under the [dependencies]
section in your Cargo.toml
:
composable = { version = "0.6", git = "https://github.com/bwoods/Architecture.git" }
-
unstable
: enable features that are still heavily under development. Unreleased features include:views
: immediate-mode user interface elements.
See the module level documentation for more.
Note that changes to
unstable
code will never be considered a semver breaking change.
Footnotes
-
As counted with
tokei --exclude src/views/ --exclude examples --exclude benches
. ↩