-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add favorite feature, connect with rootview (#34)
- Loading branch information
Showing
7 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ComposableArchitecture | ||
|
||
@Reducer | ||
public struct FavoriteReducer { | ||
public init() { } | ||
|
||
@ObservableState | ||
public struct State: Equatable { | ||
public var text: String | ||
|
||
public init(text: String = "") { | ||
self.text = text | ||
} | ||
} | ||
|
||
public enum Action { | ||
case onAppear | ||
} | ||
|
||
public var body: some ReducerOf<Self> { | ||
Reduce { state, action in | ||
switch action { | ||
case .onAppear: | ||
state.text = "Favorite Feature" | ||
return .none | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
public struct FavoriteScreen: View { | ||
private let store: StoreOf<FavoriteReducer> | ||
|
||
public init(store: StoreOf<FavoriteReducer>) { | ||
self.store = store | ||
} | ||
|
||
public var body: some View { | ||
Text(store.text) | ||
.onAppear { | ||
store.send(.onAppear) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
FavoriteScreen( | ||
store: .init( | ||
initialState: .init(), | ||
reducer: {} | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import XCTest | ||
import ComposableArchitecture | ||
@testable import FavoriteFeature | ||
|
||
final class FavoriteTests: XCTestCase { | ||
@MainActor func testExample() async throws { | ||
let store = TestStore( | ||
initialState: FavoriteReducer.State(text: "Test") | ||
) { | ||
FavoriteReducer() | ||
} | ||
await store.send(.onAppear) { | ||
$0.text = "Favorite Feature" | ||
} | ||
} | ||
} |