Skip to content

Commit

Permalink
Macro bonanza (#2553)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Silence test warnings

* wip

* wip

* wip

* update a bunch of docs

* wip

* wip

* fix

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Kill integration tests for now

* wip

* wip

* wip

* wip

* updating docs for @Reducer macro

* replaced more Reducer protocols with @Reducer

* Fixed some broken docc references

* wip

* Some @Reducer docs

* more docs

* convert some old styles to new style

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* bump

* update tutorials to use body

* update tutorials to use DML on destination state enum

* Add diagnostic

* wip

* updated a few more tests

* wip

* wip

* Add another gotcha

* wip

* wip

* wip

* fixes

* wip

* wip

* wip

* wip

* wip

* fix

* wip

* remove for now

* wip

* wip

* updated some docs

* migration guides

* more migration guide

* fix ci

* fix

* soft deprecate all apis using AnyCasePath

* wip

* Fix

* fix tests

* swift-format 509 compatibility

* wip

* wip

* Update Sources/ComposableArchitecture/Macros.swift

Co-authored-by: Mateusz Bąk <bakmatthew@icloud.com>

* wip

* wip

* update optional state case study

* remove initializer

* Don't use @State for BasicsView integration demo

* fix tests

* remove reduce diagnostics for now

* diagnose error not warning

* Update Sources/ComposableArchitecture/Macros.swift

Co-authored-by: Jesse Tipton <jesse@jessetipton.com>

* wip

* move integration tests to cron

* Revert "move integration tests to cron"

This reverts commit f9bdf2f.

* disable flakey tests on CI

* wip

* wip

* Revert "Revert "move integration tests to cron""

This reverts commit 66aafa7.

* fix

* wip

* fix

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
Co-authored-by: Mateusz Bąk <bakmatthew@icloud.com>
Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
Co-authored-by: Jesse Tipton <jesse@jessetipton.com>
  • Loading branch information
5 people authored Nov 13, 2023
1 parent 0decea3 commit 57e804f
Show file tree
Hide file tree
Showing 311 changed files with 6,085 additions and 3,611 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- case-key-paths
pull_request:
branches:
- '*'
Expand Down Expand Up @@ -59,13 +58,3 @@ jobs:
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app
- name: Run tests
run: make test-examples

integration:
name: Integration
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Select Xcode 15
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app
- name: Run tests
run: make test-integration
15 changes: 15 additions & 0 deletions .github/workflows/scheduled-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
schedule:
- cron: '30 8 * * *'
- cron: '30 20 * * *'

jobs:
integration:
name: Integration
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Select Xcode 15
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app
- name: Run tests
run: make test-integration
1 change: 1 addition & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ builder:
- platform: watchos
scheme: ComposableArchitecture
- documentation_targets: [ComposableArchitecture]
swift_version: 5.9
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
"revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a",
"version" : "1.2.2"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "5da6989aae464f324eef5c5b52bdb7974725ab81",
"version" : "1.0.0"
"revision" : "40773cbaf8d71ed5357f297b1ba4073f5b24faaa",
"version" : "1.1.0"
}
},
{
Expand All @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
Expand All @@ -68,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "65fc9e2b62727cacfab9fc60d580c284a4b9308c",
"version" : "1.1.1"
"revision" : "edd66cace818e1b1c6f1b3349bb1d8e00d6f8b01",
"version" : "1.0.0"
}
},
{
Expand Down Expand Up @@ -108,6 +108,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "35acd9468d40ae87e75991a18af6271e8124c261",
"version" : "0.2.1"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
Expand All @@ -122,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
"revision" : "ffa3cd6fc2aa62adbedd31d3efaf7c0d86a9f029",
"version" : "509.0.1"
}
},
{
Expand All @@ -140,17 +149,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation.git",
"state" : {
"revision" : "74adfb8e48724c50d0ac148c658ae5fa7dfd6b6d",
"version" : "1.0.3"
"revision" : "a3aa5d46e8bf174d773d23b030f1c103999398ac",
"version" : "1.1.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
"revision" : "302891700c7fa3b92ebde9fe7b42933f8349f3c7",
"version" : "1.0.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ComposableArchitectureMacrosTests"
BuildableName = "ComposableArchitectureMacrosTests"
BlueprintName = "ComposableArchitectureMacrosTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@ private let readMe = """

// MARK: - Feature domain

struct AlertAndConfirmationDialog: Reducer {
@Reducer
struct AlertAndConfirmationDialog {
struct State: Equatable {
@PresentationState var alert: AlertState<Action.Alert>?
@PresentationState var confirmationDialog: ConfirmationDialogState<Action.ConfirmationDialog>?
var count = 0
}

enum Action: Equatable {
enum Action {
case alert(PresentationAction<Alert>)
case alertButtonTapped
case confirmationDialog(PresentationAction<ConfirmationDialog>)
case confirmationDialogButtonTapped

enum Alert: Equatable {
enum Alert {
case incrementButtonTapped
}
enum ConfirmationDialog: Equatable {
enum ConfirmationDialog {
case incrementButtonTapped
case decrementButtonTapped
}
Expand Down Expand Up @@ -97,8 +98,8 @@ struct AlertAndConfirmationDialog: Reducer {
return .none
}
}
.ifLet(\.$alert, action: /Action.alert)
.ifLet(\.$confirmationDialog, action: /Action.confirmationDialog)
.ifLet(\.$alert, action: \.alert)
.ifLet(\.$confirmationDialog, action: \.confirmationDialog)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ private let readMe = """

// MARK: - Feature domain

struct Animations: Reducer {
@Reducer
struct Animations {
struct State: Equatable {
@PresentationState var alert: AlertState<Action.Alert>?
var circleCenter: CGPoint?
var circleColor = Color.black
var isCircleScaled = false
}

enum Action: Equatable, Sendable {
enum Action: Sendable {
case alert(PresentationAction<Alert>)
case circleScaleToggleChanged(Bool)
case rainbowButtonTapped
case resetButtonTapped
case setColor(Color)
case tapped(CGPoint)

enum Alert: Equatable, Sendable {
enum Alert: Sendable {
case resetConfirmationButtonTapped
}
}
Expand Down Expand Up @@ -93,7 +94,7 @@ struct Animations: Reducer {
return .none
}
}
.ifLet(\.$alert, action: /Action.alert)
.ifLet(\.$alert, action: \.alert)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ private let readMe = """

// MARK: - Feature domain

struct BindingBasics: Reducer {
@Reducer
struct BindingBasics {
struct State: Equatable {
var sliderValue = 5.0
var stepCount = 10
Expand All @@ -35,24 +36,26 @@ struct BindingBasics: Reducer {
case toggleChanged(isOn: Bool)
}

func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case let .sliderValueChanged(value):
state.sliderValue = value
return .none

case let .stepCountChanged(count):
state.sliderValue = .minimum(state.sliderValue, Double(count))
state.stepCount = count
return .none

case let .textChanged(text):
state.text = text
return .none

case let .toggleChanged(isOn):
state.toggleIsOn = isOn
return .none
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case let .sliderValueChanged(value):
state.sliderValue = value
return .none

case let .stepCountChanged(count):
state.sliderValue = .minimum(state.sliderValue, Double(count))
state.stepCount = count
return .none

case let .textChanged(text):
state.text = text
return .none

case let .toggleChanged(isOn):
state.toggleIsOn = isOn
return .none
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ private let readMe = """

// MARK: - Feature domain

struct BindingForm: Reducer {
@Reducer
struct BindingForm {
struct State: Equatable {
@BindingState var sliderValue = 5.0
@BindingState var stepCount = 10
@BindingState var text = ""
@BindingState var toggleIsOn = false
}

enum Action: BindableAction, Equatable {
enum Action: BindableAction {
case binding(BindingAction<State>)
case resetButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ private let readMe = """

// MARK: - Feature domain

struct TwoCounters: Reducer {
@Reducer
struct TwoCounters {
struct State: Equatable {
var counter1 = Counter.State()
var counter2 = Counter.State()
}

enum Action: Equatable {
enum Action {
case counter1(Counter.Action)
case counter2(Counter.Action)
}

var body: some Reducer<State, Action> {
Scope(state: \.counter1, action: /Action.counter1) {
Scope(state: \.counter1, action: \.counter1) {
Counter()
}
Scope(state: \.counter2, action: /Action.counter2) {
Scope(state: \.counter2, action: \.counter2) {
Counter()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ private let readMe = """

// MARK: - Feature domain

struct Counter: Reducer {
@Reducer
struct Counter {
struct State: Equatable {
var count = 0
}

enum Action: Equatable {
enum Action {
case decrementButtonTapped
case incrementButtonTapped
}

func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .decrementButtonTapped:
state.count -= 1
return .none
case .incrementButtonTapped:
state.count += 1
return .none
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .decrementButtonTapped:
state.count -= 1
return .none
case .incrementButtonTapped:
state.count += 1
return .none
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ private let readMe = """

// MARK: - Feature domain

struct FocusDemo: Reducer {
@Reducer
struct FocusDemo {
struct State: Equatable {
@BindingState var focusedField: Field?
@BindingState var password: String = ""
Expand All @@ -20,7 +21,7 @@ struct FocusDemo: Reducer {
}
}

enum Action: BindableAction, Equatable {
enum Action: BindableAction {
case binding(BindingAction<State>)
case signInButtonTapped
}
Expand Down
Loading

0 comments on commit 57e804f

Please sign in to comment.