Skip to content

Commit

Permalink
Merge pull request #11 from riiid/feature/update_TCA
Browse files Browse the repository at this point in the history
Update TCA to 1.1.0
  • Loading branch information
yermukhanbet authored Aug 21, 2023
2 parents f29352f + 817d99c commit bd128a9
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 94 deletions.
55 changes: 41 additions & 14 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "aa3e575929f2bcc5bad012bd2575eae716cbcdf7",
"version" : "0.8.0"
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
Expand All @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "bb436421f57269fbcfe7360735985321585a86e5",
"version" : "0.10.1"
"revision" : "5da6989aae464f324eef5c5b52bdb7974725ab81",
"version" : "1.0.0"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "692ec4f5429a667bdd968c7260dfa2b23adfeffc",
"version" : "0.1.4"
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
}
},
{
Expand All @@ -59,35 +59,62 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "1fcd53fc875bade47d850749ea53c324f74fd64d",
"version" : "0.45.0"
"revision" : "f62ba37cc0c51acb89f6dd1f552f6a1f9c58027c",
"version" : "1.1.0"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "ea631ce892687f5432a833312292b80db238186a",
"version" : "1.0.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "819d9d370cd721c9d87671e29d947279292e4541",
"version" : "0.6.0"
"revision" : "edd66cace818e1b1c6f1b3349bb1d8e00d6f8b01",
"version" : "1.0.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "4e1eb6e28afe723286d8cc60611237ffbddba7c5",
"version" : "1.0.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "bfb0d43e75a15b6dfac770bf33479e8393884a36",
"version" : "0.4.1"
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "f5bcdac5b6bb3f826916b14705f37a3937c2fd34",
"version" : "1.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "16e6409ee82e1b81390bdffbf217b9c08ab32784",
"version" : "0.5.0"
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
targets: ["TCALogsSheetKit"]),
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "0.45.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.1.0"),
.package(url: "https://github.com/riiid/LogsSheetKit", from: "1.0.0")
],
targets: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/TCALogsSheetKit/Examples/CounterReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ComposableArchitecture
import Foundation
import LogsSheetKit

struct Counter: ReducerProtocol {
struct Counter: Reducer {
struct State: Equatable {
var logs: [ActionLog] = []
var count = 0
Expand All @@ -21,7 +21,7 @@ struct Counter: ReducerProtocol {

}

var body: some ReducerProtocol<State, Action> {
var body: some Reducer<State, Action> {
Reduce { (state, action) in
switch action {
case .increase:
Expand Down
16 changes: 11 additions & 5 deletions Sources/TCALogsSheetKit/Examples/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ struct CounterView: View {
@State private var isPresented: Bool = false

var body: some View {
WithViewStore(self.store) { store in
WithViewStore(
self.store,
observe: { $0 }
) { store in
NavigationView {
VStack {
Spacer()
Expand Down Expand Up @@ -49,9 +52,12 @@ struct CounterView: View {

struct CounterView_Previews: PreviewProvider {
static var previews: some View {
CounterView(store: Store(
initialState: Counter.State(),
reducer: Counter()
))
CounterView(
store: .init(
initialState: Counter.State(),
reducer: {
Counter()
})
)
}
}
36 changes: 3 additions & 33 deletions Sources/TCALogsSheetKit/TCALogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,11 @@ import Foundation
import ComposableArchitecture
import LogsSheetKit

extension AnyReducer {
extension Reducer {
/// Saves each action run through the reducer as the log message if debug build configuration is on
/// - Parameters:
/// - isDebug: is debug configuration on
public func log(isDebug: Bool) -> Self {
AnyReducer.init { state, action, environment in
if isDebug {
LogsSheetManager.shared.log(message: "\(action)")
}
return self.run(&state, action, environment)
}
}

/// Saves the custom log message if debug build configuration is on
/// - Parameters:
/// - isDebug: is debug configuration on
/// - message: custom log message
public func log(
isDebug: Bool,
with message: @escaping ((Action) -> String)
) -> Self {
AnyReducer.init { state, action, environment in
if isDebug {
LogsSheetManager.shared.log(message: message(action))
}
return self.run(&state, action, environment)
}
}
}

extension ReducerProtocol {
/// Saves each action run through the reducer as the log message if debug build configuration is on
/// - Parameters:
/// - isDebug: is debug configuration on
public func log(isDebug: Bool) -> some ReducerProtocol<State, Action> {
public func log(isDebug: Bool) -> some Reducer<State, Action> {
Reduce { state, action in
if isDebug {
LogsSheetManager.shared.log(message: "\(action)")
Expand All @@ -60,7 +30,7 @@ extension ReducerProtocol {
public func log(
isDebug: Bool,
with message: @escaping ((Action) -> String)
) -> some ReducerProtocol<State, Action> {
) -> some Reducer<State, Action> {
Reduce { state, action in
if isDebug {
LogsSheetManager.shared.log(message: message(action))
Expand Down
4 changes: 2 additions & 2 deletions TCALoggerSample/TCALoggerSample/Counter/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import ComposableArchitecture
import Dependencies
import TCALogsSheetKit

public struct Counter: ReducerProtocol {
public struct Counter: Reducer {
@Dependency(\.serviceCounter) private var serviceCounter

public init() {}

public var body: some ReducerProtocol<State, Action> {
public var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .increase:
Expand Down
12 changes: 8 additions & 4 deletions TCALoggerSample/TCALoggerSample/Counter/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public struct CounterView: View {
@State private var isPresented: Bool = false

public var body: some View {
WithViewStore(self.store) { store in
WithViewStore(
self.store,
observe: { $0 }
) { store in
NavigationView {
VStack(spacing: 20) {
Spacer()
Expand Down Expand Up @@ -80,8 +83,9 @@ public struct CounterView: View {
struct CounterView_Previews: PreviewProvider {
static var previews: some View {
CounterView(store: Store(
initialState: Counter.State(),
reducer: Counter()
))
initialState: Counter.State()
) {
Counter()
})
}
}
4 changes: 2 additions & 2 deletions TCALoggerSample/TCALoggerSample/Emoji/EmojiPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import ComposableArchitecture
import Dependencies

public struct EmojiPicker: ReducerProtocol {
public struct EmojiPicker: Reducer {
@Dependency(\.serviceBackgroundChanger) private var serviceBackgroundChanger

public init() {}

public var body: some ReducerProtocol<State, Action> {
public var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .changeEmoji:
Expand Down
27 changes: 15 additions & 12 deletions TCALoggerSample/TCALoggerSample/Emoji/EmojiPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ import ComposableArchitecture
// MARK: - View

public struct EmojiPickerView: View {
@ObservedObject
private var viewStore: ViewStoreOf<EmojiPicker>
private let store: StoreOf<EmojiPicker>

public init(store: StoreOf<EmojiPicker>) {
self.viewStore = .init(store)
self.store = store
}

public var body: some View {
VStack(spacing: 20) {
if let currentEmojie = viewStore.currentEmoji {
Text("\(currentEmojie.rawValue)")
}
Button("change emoji") {
viewStore.send(.changeEmoji)
WithViewStore(
store,
observe: \.currentEmoji
) { viewStore in
VStack(spacing: 20) {
if let currentEmojie = viewStore.state {
Text("\(currentEmojie.rawValue)")
}
Button("change emoji") {
viewStore.send(.changeEmoji)
}
}
}
}
Expand All @@ -42,7 +44,8 @@ struct EmojiPicker_Previews: PreviewProvider {
}

static let store: StoreOf<EmojiPicker> = .init(
initialState: .init(),
reducer: EmojiPicker()
)
initialState: .init()
) {
EmojiPicker()
}
}
8 changes: 7 additions & 1 deletion TCALoggerSample/TCALoggerSample/TCALoggerSampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import ComposableArchitecture
struct TCALoggerSampleApp: App {
var body: some Scene {
WindowGroup {
CounterView(store: Store(initialState: Counter.State(), reducer: Counter()))
CounterView(
store: Store(
initialState: Counter.State()
) {
Counter()
}
)
}
}
}
Loading

0 comments on commit bd128a9

Please sign in to comment.