Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vmanot/reactor

The most advanced state management framework for SwiftUI.
https://github.com/vmanot/reactor

Last synced: 5 days ago
JSON representation

The most advanced state management framework for SwiftUI.

Awesome Lists containing this project

README

        

# Reactor
A state management framework for SwiftUI.

## Why

Reactor is a Flux-inspired, reactive state management

```swift
struct ExampleView: ReactorView {
let reactor: Reactor

init(reactor: Reactor) {
self.reactor = reactor
}

func makeBody(reactor: Reactor) -> some View {
Group {
if reactor.status(of: .foo) == .active {
ActivityIndicator()
} else {
reactor.taskButton(for: .foo) {
Text("Run foo!")
}
}
}
}
}

extension ExampleView {
struct Reactor: ViewReactor {
enum Action: Hashable {
case foo
}

@ViewReactorEnvironment() var environment
}
}

extension ExampleView.Reactor {
func task(for action: Action) -> ActionTask {
switch action {
case .foo:
return Just(())
.delay(for: .seconds(1), scheduler: DispatchQueue.main)
.eraseToActionTask()
}
}
}
```