Skip to content

Commit

Permalink
@Reducer macro enhancements (#2795)
Browse files Browse the repository at this point in the history
* updated binding docs

* adding docs

* clean up

* wip

* wip

* wip

* clean up

* clean up

* clean up

* wip;

* lots of fixes

* update more docs

* fix

* wip

* wip

* Remove ObservationRegistrarWrapper. (#2634)

* Remove ObservationRegistrarWrapper.

* Delete Sources/ComposableArchitecture/Internal/ObservationRegistrarWrapper.swift

---------

Co-authored-by: Stephen Celis <[email protected]>

* more docs

* update docs

* a few more tests

* fix

* wip

* wip

* wip

* Cache data in store collections (#2635)

* fix tutorial highlighting

* wip

* wip

* wip

* wip

* tests for observation of special domain types

* another test

* fix

* wip

* Implement memoization for perception checks (#2630)

* Implement memoization for isInSwiftUIBody

* tidy up

* Perception caching updates (#2649)

* Small updates to perception caching.

* wip

* debug

* some more macro tests

* syncups tutorial beginnings

* wip

* wip

* wip

* wip

* wip

* merge fixes

* wip

* update tests

* fix

* fix

* fix perception checking in store

* rename task local

* delete old test

* deprecate test using old apis

* fix test

* perception tests for store

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Opt out of key path for Store.ifLet

* sync ups

* lots more sync up tutorial

* more sync ups tutorial

* wip

* wip

* wio

* wip

* wip

* wip

* updated references of 1.6 to 1.7

* wip

* no need to force unwrap here

* fixed crash in ForEach with bindings

* more sync ups tutorial

* more sync ups tutorial

* wip

* more sync ups

* wip

* wip

* Better support for observing copies of values (#2650)

* Explore using _modify

* wip

* wip

* wip

* wip

* wip

* wip

* more tests

* wip

* get another failing test for an edge case

* wip

* tests all passing

* flag for determining when new state was created

* wip

* clean up

* wip

* wip

* wip;

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* New test that currently fails.

* wip

* wip

* Update Sources/ComposableArchitectureMacros/PresentsMacro.swift

* wip

* remove redundant attached member attribute

* storage

* cleanup

* more benchmarks and tests

* wip

* wip

* wip

* wip

* update tests

* wip

* wip

---------

Co-authored-by: Brandon Williams <[email protected]>

* wip

* wip

* wip

* swift-format

* fix

* wip

* wip

* wip

* wip

* Perception

* wip

* wip

* clean up shared state

* fix shared state tests

* wip

* add alert test

* wip

* wip

* wip

* wip

* Use transaction in binding

* wip

* wip

* wip

* wip

* wip

* wip

* uikit

* keep references to controllers when presenting so that we can properly dismiss

* change order of features in shared state demo

* wip

* cleanup

* cleanup

* wip

* wip

* wip

* Fix perception checking for effect actions.

* wip

* wip

* wip

* Fix perception checking for effect actions.

* wip

* wip

* remove sync ups tutorial

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* @Reducer macro will insert protocol requirements if missing

* wip

* fixes

* fix

* wip

* wip

* wip

* docs for observe function for uikit

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Add cancellation to observation'

* re-record integration test snapshots

* fixed some todos

* update test

* remove 5.9.2 checks

* wip

* wip

* improve docs

* update docs

* updates

* lots of fixes

* more docs

* remove unneeded file;

* wip

* wip

* wip

* update readme and getting started

* wip

* wip

* simplify

* migration stuff

* wip

* Update Models.swift

* wip

* wip

* wip

* Update Bindings.md

* wip

* wip

* wip

* wip

* fix

* wip

* wip

* wip

* wip

* wip

Co-authored-by: Kabir Oberai <[email protected]>

* lots of docs and some fixes

* more docs

* more docs

* wip

* upate integration tests to use enum destination macro

* re-org migration guide

* wip

* wip

* docs for other enum reducer macros

* update ephemeral state docs

* wip

* move docs for reducer protocol and macro into single article

* mention observable state

* wip

* updated docs and some macro tests

* wip

* wip

* cleanup

* wip

* wip

* wip

* revert 16

* wip

* clean up

* Revert "clean up"

This reverts commit 49e7308.

* Availability fixes

* comment out tests crashing the compiler

* wip

* fix ttt tests

* wip

---------

Co-authored-by: Brandon Williams <[email protected]>
Co-authored-by: Brandon Williams <[email protected]>
Co-authored-by: George Scott <[email protected]>
Co-authored-by: Kabir Oberai <[email protected]>
  • Loading branch information
5 people authored Feb 12, 2024
1 parent 08c7c6b commit f75f938
Show file tree
Hide file tree
Showing 62 changed files with 2,715 additions and 1,448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,11 @@ private let readMe = """

@Reducer
struct MultipleDestinations {
@Reducer
public struct Destination {
@ObservableState
public enum State: Equatable {
case drillDown(Counter.State)
case popover(Counter.State)
case sheet(Counter.State)
}

public enum Action {
case drillDown(Counter.Action)
case popover(Counter.Action)
case sheet(Counter.Action)
}

public var body: some Reducer<State, Action> {
Scope(state: \.drillDown, action: \.drillDown) {
Counter()
}
Scope(state: \.sheet, action: \.sheet) {
Counter()
}
Scope(state: \.popover, action: \.popover) {
Counter()
}
}
@Reducer(state: .equatable)
enum Destination {
case drillDown(Counter)
case popover(Counter)
case sheet(Counter)
}

@ObservableState
Expand Down Expand Up @@ -64,9 +43,7 @@ struct MultipleDestinations {
return .none
}
}
.ifLet(\.$destination, action: \.destination) {
Destination()
}
.ifLet(\.$destination, action: \.destination)
}
}

Expand Down
95 changes: 30 additions & 65 deletions Examples/CaseStudies/SwiftUICaseStudies/03-NavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ private let readMe = """

@Reducer
struct NavigationDemo {
@Reducer(state: .equatable)
enum Path {
case screenA(ScreenA)
case screenB(ScreenB)
case screenC(ScreenC)
}

@ObservableState
struct State: Equatable {
var path = StackState<Path.State>()
Expand All @@ -27,23 +34,23 @@ struct NavigationDemo {
return .none

case .goToABCButtonTapped:
state.path.append(.screenA())
state.path.append(.screenB())
state.path.append(.screenC())
state.path.append(.screenA(ScreenA.State()))
state.path.append(.screenB(ScreenB.State()))
state.path.append(.screenC(ScreenC.State()))
return .none

case let .path(action):
switch action {
case .element(id: _, action: .screenB(.screenAButtonTapped)):
state.path.append(.screenA())
state.path.append(.screenA(ScreenA.State()))
return .none

case .element(id: _, action: .screenB(.screenBButtonTapped)):
state.path.append(.screenB())
state.path.append(.screenB(ScreenB.State()))
return .none

case .element(id: _, action: .screenB(.screenCButtonTapped)):
state.path.append(.screenC())
state.path.append(.screenC(ScreenC.State()))
return .none

default:
Expand All @@ -55,37 +62,7 @@ struct NavigationDemo {
return .none
}
}
.forEach(\.path, action: \.path) {
Path()
}
}

@Reducer
struct Path {
@ObservableState
enum State: Equatable {
case screenA(ScreenA.State = .init())
case screenB(ScreenB.State = .init())
case screenC(ScreenC.State = .init())
}

enum Action {
case screenA(ScreenA.Action)
case screenB(ScreenB.Action)
case screenC(ScreenC.Action)
}

var body: some Reducer<State, Action> {
Scope(state: \.screenA, action: \.screenA) {
ScreenA()
}
Scope(state: \.screenB, action: \.screenB) {
ScreenB()
}
Scope(state: \.screenC, action: \.screenC) {
ScreenC()
}
}
.forEach(\.path, action: \.path)
}
}

Expand All @@ -100,15 +77,15 @@ struct NavigationDemoView: View {
Section {
NavigationLink(
"Go to screen A",
state: NavigationDemo.Path.State.screenA()
state: NavigationDemo.Path.State.screenA(ScreenA.State())
)
NavigationLink(
"Go to screen B",
state: NavigationDemo.Path.State.screenB()
state: NavigationDemo.Path.State.screenB(ScreenB.State())
)
NavigationLink(
"Go to screen C",
state: NavigationDemo.Path.State.screenC()
state: NavigationDemo.Path.State.screenC(ScreenC.State())
)
}

Expand All @@ -120,19 +97,13 @@ struct NavigationDemoView: View {
}
.navigationTitle("Root")
} destination: { store in
switch store.state {
case .screenA:
if let store = store.scope(state: \.screenA, action: \.screenA) {
ScreenAView(store: store)
}
case .screenB:
if let store = store.scope(state: \.screenB, action: \.screenB) {
ScreenBView(store: store)
}
case .screenC:
if let store = store.scope(state: \.screenC, action: \.screenC) {
ScreenCView(store: store)
}
switch store.case {
case let .screenA(store):
ScreenAView(store: store)
case let .screenB(store):
ScreenBView(store: store)
case let .screenC(store):
ScreenCView(store: store)
}
}
.safeAreaInset(edge: .bottom) {
Expand Down Expand Up @@ -318,15 +289,15 @@ struct ScreenAView: View {
Section {
NavigationLink(
"Go to screen A",
state: NavigationDemo.Path.State.screenA(.init(count: store.count))
state: NavigationDemo.Path.State.screenA(ScreenA.State(count: store.count))
)
NavigationLink(
"Go to screen B",
state: NavigationDemo.Path.State.screenB()
state: NavigationDemo.Path.State.screenB(ScreenB.State())
)
NavigationLink(
"Go to screen C",
state: NavigationDemo.Path.State.screenC(.init(count: store.count))
state: NavigationDemo.Path.State.screenC(ScreenC.State(count: store.count))
)
}
}
Expand Down Expand Up @@ -460,11 +431,11 @@ struct ScreenCView: View {
)
NavigationLink(
"Go to screen B",
state: NavigationDemo.Path.State.screenB()
state: NavigationDemo.Path.State.screenB(ScreenB.State())
)
NavigationLink(
"Go to screen C",
state: NavigationDemo.Path.State.screenC()
state: NavigationDemo.Path.State.screenC(ScreenC.State())
)
}
}
Expand All @@ -476,13 +447,7 @@ struct ScreenCView: View {

#Preview {
NavigationDemoView(
store: Store(
initialState: NavigationDemo.State(
path: StackState([
.screenA(ScreenA.State())
])
)
) {
store: Store(initialState: NavigationDemo.State()) {
NavigationDemo()
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI

@Reducer
private struct EscapedWithViewStoreTestCase {
enum Action: Equatable, Sendable {
enum Action: Sendable {
case incr
case decr
}
Expand Down
Loading

0 comments on commit f75f938

Please sign in to comment.