From 3539af021dc91f8e1262963f201983ec051e0e01 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Wed, 5 Oct 2022 14:46:54 +0900 Subject: [PATCH 01/12] :heavy_plus_sign: Added ComposableArchitecture --- Package.resolved | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ Package.swift | 6 +++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Package.resolved b/Package.resolved index cd1cea7..7c35059 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,14 @@ { "pins" : [ + { + "identity" : "combine-schedulers", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/combine-schedulers", + "state" : { + "revision" : "aa3e575929f2bcc5bad012bd2575eae716cbcdf7", + "version" : "0.8.0" + } + }, { "identity" : "spindicator", "kind" : "remoteSourceControl", @@ -8,6 +17,60 @@ "revision" : "43600857729d9efff046dc6673e6f94e095882c7", "version" : "1.6.4" } + }, + { + "identity" : "swift-case-paths", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-case-paths", + "state" : { + "revision" : "7346701ea29da0a85d4403cf3d7a589a58ae3dee", + "version" : "0.9.2" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections", + "state" : { + "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-composable-architecture", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-composable-architecture", + "state" : { + "revision" : "9ea8c763061287052a68d5e6723fed45e898b7d9", + "version" : "0.40.2" + } + }, + { + "identity" : "swift-custom-dump", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-custom-dump", + "state" : { + "revision" : "819d9d370cd721c9d87671e29d947279292e4541", + "version" : "0.6.0" + } + }, + { + "identity" : "swift-identified-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-identified-collections", + "state" : { + "revision" : "bfb0d43e75a15b6dfac770bf33479e8393884a36", + "version" : "0.4.1" + } + }, + { + "identity" : "xctest-dynamic-overlay", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", + "state" : { + "revision" : "30314f1ece684dd60679d598a9b89107557b67d9", + "version" : "0.4.1" + } } ], "version" : 2 diff --git a/Package.swift b/Package.swift index 11c9b37..2541140 100644 --- a/Package.swift +++ b/Package.swift @@ -13,13 +13,15 @@ let package = Package( targets: ["LogsSheetKit"]), ], dependencies: [ - .package(url: "https://github.com/ivanvorobei/SPIndicator", .upToNextMajor(from: "1.6.0")) + .package(url: "https://github.com/ivanvorobei/SPIndicator", .upToNextMajor(from: "1.6.0")), + .package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMajor(from: "0.40.0")) ], targets: [ .target( name: "LogsSheetKit", dependencies: [ - "SPIndicator" + "SPIndicator", + .product(name: "ComposableArchitecture", package: "swift-composable-architecture") ]), .testTarget( name: "LogsSheetKitTests", From 05f03c695b65c54eca0d8a588d77880f3662bd1a Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Wed, 5 Oct 2022 14:47:55 +0900 Subject: [PATCH 02/12] :sparkles: Added log function to Reducer, LoggableState --- .../Extensions/TCA/Reducer+Log.swift | 24 +++++++++++++++++++ .../{ => Extensions/View}/View+Modified.swift | 0 2 files changed, 24 insertions(+) create mode 100644 Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift rename Sources/LogsSheetKit/{ => Extensions/View}/View+Modified.swift (100%) diff --git a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift new file mode 100644 index 0000000..9523dd1 --- /dev/null +++ b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -0,0 +1,24 @@ +// +// Reducer+Log.swift +// +// +// Created by Yessen Yermukhanbet on 2022/10/05. +// + +import Foundation +import ComposableArchitecture + +extension Reducer where State: LoggableState { + func log() -> Self { + .init { state, action, environment in + #if DEBUG || STG + state.logs.append(.init(message: "\(action)")) + #endif + return self.run(&state, action, environment) + } + } +} + +protocol LoggableState: Equatable { + var logs: [ActionLog] { get set } +} diff --git a/Sources/LogsSheetKit/View+Modified.swift b/Sources/LogsSheetKit/Extensions/View/View+Modified.swift similarity index 100% rename from Sources/LogsSheetKit/View+Modified.swift rename to Sources/LogsSheetKit/Extensions/View/View+Modified.swift From 31f65bfe73d03a7f4b71b063f0b3c66c95eade09 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Wed, 5 Oct 2022 18:01:30 +0900 Subject: [PATCH 03/12] :sparkles: Add LoggableState --- .../Extensions/TCA/Reducer+Log.swift | 5 +--- Sources/LogsSheetKit/LoggableState.swift | 29 +++++++++++++++++++ .../LogsSheetKitTests/LogsSheetKitTests.swift | 7 ----- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 Sources/LogsSheetKit/LoggableState.swift delete mode 100644 Tests/LogsSheetKitTests/LogsSheetKitTests.swift diff --git a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift index 9523dd1..f7c3273 100644 --- a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift +++ b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -3,6 +3,7 @@ // // // Created by Yessen Yermukhanbet on 2022/10/05. +// Copyright © 2022 Riiid Inc. All rights reserved. // import Foundation @@ -18,7 +19,3 @@ extension Reducer where State: LoggableState { } } } - -protocol LoggableState: Equatable { - var logs: [ActionLog] { get set } -} diff --git a/Sources/LogsSheetKit/LoggableState.swift b/Sources/LogsSheetKit/LoggableState.swift new file mode 100644 index 0000000..2f3a89e --- /dev/null +++ b/Sources/LogsSheetKit/LoggableState.swift @@ -0,0 +1,29 @@ +// +// File.swift +// +// +// Created by Yessen Yermukhanbet on 2022/10/05. +// Copyright © 2022 Riiid Inc. All rights reserved. +// + +import Foundation + +public protocol LoggableState: Equatable { + var logs: [ActionLog] { get set } +} + +extension LoggableState { + var logs: [ActionLog] { + get { + return GlobalLogs.shared.logs + } + set { + GlobalLogs.shared.logs = newValue + } + } +} + +struct GlobalLogs { + static var shared: GlobalLogs = GlobalLogs() + var logs: [ActionLog] = [] +} diff --git a/Tests/LogsSheetKitTests/LogsSheetKitTests.swift b/Tests/LogsSheetKitTests/LogsSheetKitTests.swift deleted file mode 100644 index 317f789..0000000 --- a/Tests/LogsSheetKitTests/LogsSheetKitTests.swift +++ /dev/null @@ -1,7 +0,0 @@ -import XCTest -@testable import LogsSheetKit - -final class LogsSheetKitTests: XCTestCase { - func testExample() throws { - } -} From 4ad99f33ccddebfc08b9a4b82c00ef755734db1b Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Wed, 5 Oct 2022 18:01:55 +0900 Subject: [PATCH 04/12] :white_check_mark: Add LoggableStateTests, LogsSheetKitTests --- .../xcschemes/LogsSheetKit.xcscheme | 91 +++++++++++++++++++ .../xcschemes/LogsSheetKitTests.xcscheme | 77 ++++++++++++++++ .../LoggableStateTests.swift | 41 +++++++++ 3 files changed, 209 insertions(+) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme create mode 100644 Tests/LogsSheetKitTests/LoggableStateTests.swift diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme new file mode 100644 index 0000000..2445259 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme new file mode 100644 index 0000000..e541887 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/LogsSheetKitTests/LoggableStateTests.swift b/Tests/LogsSheetKitTests/LoggableStateTests.swift new file mode 100644 index 0000000..6c0c413 --- /dev/null +++ b/Tests/LogsSheetKitTests/LoggableStateTests.swift @@ -0,0 +1,41 @@ +// +// LoggableStateTests.swift +// +// +// Created by Yessen Yermukhanbet on 2022/10/05. +// Copyright © 2022 Riiid Inc. All rights reserved. +// + +import XCTest +@testable import LogsSheetKit + +final class LoggableStateTests: XCTestCase { + + override func setUp() { + super.setUp() + GlobalLogs.shared.logs = [] // Clean up before each test + } + + private struct StubState: LoggableState { } + + func testLoggableStateAtTheBeginningLogsEmpty() { + let stub: StubState = StubState() + XCTAssertTrue(stub.logs.count == 0) + } + + func testLoggableStateAppendsLogs() { + var stub: StubState = StubState() + + let logs: [ActionLog] = [ + ActionLog(message: "stub"), + ActionLog(message: "stub"), + ActionLog(message: "stub"), + ] + + for log in logs { + stub.logs.append(log) + } + + XCTAssertTrue(stub.logs.count == logs.count) + } +} From 6df2d3af3e9ed60af1fdccd2c64bda4c182b8b82 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Wed, 5 Oct 2022 18:08:08 +0900 Subject: [PATCH 05/12] :recycle: make internal -> public --- Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift | 2 +- Sources/LogsSheetKit/Extensions/View/View+Modified.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift index f7c3273..3e3dbce 100644 --- a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift +++ b/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -10,7 +10,7 @@ import Foundation import ComposableArchitecture extension Reducer where State: LoggableState { - func log() -> Self { + public func log() -> Self { .init { state, action, environment in #if DEBUG || STG state.logs.append(.init(message: "\(action)")) diff --git a/Sources/LogsSheetKit/Extensions/View/View+Modified.swift b/Sources/LogsSheetKit/Extensions/View/View+Modified.swift index 2afbe61..dfac867 100644 --- a/Sources/LogsSheetKit/Extensions/View/View+Modified.swift +++ b/Sources/LogsSheetKit/Extensions/View/View+Modified.swift @@ -8,7 +8,7 @@ import SwiftUI extension View { - func modified(@ViewBuilder modification: (Self) -> Modified) -> some View { + public func modified(@ViewBuilder modification: (Self) -> Modified) -> some View { return modification(self) } } From 37feca651cc6886b07ae4adc77ff658688c525e5 Mon Sep 17 00:00:00 2001 From: Yessen Date: Wed, 5 Oct 2022 23:13:14 +0900 Subject: [PATCH 06/12] :truck: Rename to ComposableLogsSheetKit --- Package.swift | 12 ++++++------ .../ActionLog.swift | 0 .../Extensions/TCA/Reducer+Log.swift | 0 .../Extensions/View/View+Modified.swift | 0 .../LoggableState.swift | 0 .../LogsSheet.swift | 0 .../LoggableStateTests.swift | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename Sources/{LogsSheetKit => ComposableLogsSheetKit}/ActionLog.swift (100%) rename Sources/{LogsSheetKit => ComposableLogsSheetKit}/Extensions/TCA/Reducer+Log.swift (100%) rename Sources/{LogsSheetKit => ComposableLogsSheetKit}/Extensions/View/View+Modified.swift (100%) rename Sources/{LogsSheetKit => ComposableLogsSheetKit}/LoggableState.swift (100%) rename Sources/{LogsSheetKit => ComposableLogsSheetKit}/LogsSheet.swift (100%) rename Tests/{LogsSheetKitTests => ComposableLogsSheetKitTests}/LoggableStateTests.swift (95%) diff --git a/Package.swift b/Package.swift index 2541140..a117968 100644 --- a/Package.swift +++ b/Package.swift @@ -3,14 +3,14 @@ import PackageDescription let package = Package( - name: "LogsSheetKit", + name: "ComposableLogsSheetKit", platforms: [ .iOS(.v14) ], products: [ .library( - name: "LogsSheetKit", - targets: ["LogsSheetKit"]), + name: "ComposableLogsSheetKit", + targets: ["ComposableLogsSheetKit"]), ], dependencies: [ .package(url: "https://github.com/ivanvorobei/SPIndicator", .upToNextMajor(from: "1.6.0")), @@ -18,13 +18,13 @@ let package = Package( ], targets: [ .target( - name: "LogsSheetKit", + name: "ComposableLogsSheetKit", dependencies: [ "SPIndicator", .product(name: "ComposableArchitecture", package: "swift-composable-architecture") ]), .testTarget( - name: "LogsSheetKitTests", - dependencies: ["LogsSheetKit"]), + name: "ComposableLogsSheetKitTests", + dependencies: ["ComposableLogsSheetKit"]), ] ) diff --git a/Sources/LogsSheetKit/ActionLog.swift b/Sources/ComposableLogsSheetKit/ActionLog.swift similarity index 100% rename from Sources/LogsSheetKit/ActionLog.swift rename to Sources/ComposableLogsSheetKit/ActionLog.swift diff --git a/Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift similarity index 100% rename from Sources/LogsSheetKit/Extensions/TCA/Reducer+Log.swift rename to Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift diff --git a/Sources/LogsSheetKit/Extensions/View/View+Modified.swift b/Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift similarity index 100% rename from Sources/LogsSheetKit/Extensions/View/View+Modified.swift rename to Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift diff --git a/Sources/LogsSheetKit/LoggableState.swift b/Sources/ComposableLogsSheetKit/LoggableState.swift similarity index 100% rename from Sources/LogsSheetKit/LoggableState.swift rename to Sources/ComposableLogsSheetKit/LoggableState.swift diff --git a/Sources/LogsSheetKit/LogsSheet.swift b/Sources/ComposableLogsSheetKit/LogsSheet.swift similarity index 100% rename from Sources/LogsSheetKit/LogsSheet.swift rename to Sources/ComposableLogsSheetKit/LogsSheet.swift diff --git a/Tests/LogsSheetKitTests/LoggableStateTests.swift b/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift similarity index 95% rename from Tests/LogsSheetKitTests/LoggableStateTests.swift rename to Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift index 6c0c413..8d6cfc4 100644 --- a/Tests/LogsSheetKitTests/LoggableStateTests.swift +++ b/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift @@ -7,7 +7,7 @@ // import XCTest -@testable import LogsSheetKit +@testable import ComposableLogsSheetKit final class LoggableStateTests: XCTestCase { From 59412017ea7f9fd448bcba094690b24058960e19 Mon Sep 17 00:00:00 2001 From: Yessen Date: Wed, 5 Oct 2022 23:54:41 +0900 Subject: [PATCH 07/12] :fire: Remove LogsSheet related files --- .../ComposableLogsSheetKit/ActionLog.swift | 19 --- .../Extensions/View/View+Modified.swift | 14 -- .../ComposableLogsSheetKit/LogsSheet.swift | 146 ------------------ 3 files changed, 179 deletions(-) delete mode 100644 Sources/ComposableLogsSheetKit/ActionLog.swift delete mode 100644 Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift delete mode 100644 Sources/ComposableLogsSheetKit/LogsSheet.swift diff --git a/Sources/ComposableLogsSheetKit/ActionLog.swift b/Sources/ComposableLogsSheetKit/ActionLog.swift deleted file mode 100644 index 88d51c9..0000000 --- a/Sources/ComposableLogsSheetKit/ActionLog.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// ActionLog.swift -// -// -// Created by Yessen Yermukhanbet on 2022/10/04. -// Copyright © 2022 Riiid Inc. All rights reserved. -// - -import Foundation - -public struct ActionLog: Equatable, Identifiable { - public var id: UUID = .init() - public var message: String - public var timeStamp: Date = Date() - - public init(message: String) { - self.message = message - } -} diff --git a/Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift b/Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift deleted file mode 100644 index dfac867..0000000 --- a/Sources/ComposableLogsSheetKit/Extensions/View/View+Modified.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// View+Modified.swift -// -// Created by Dongkyu Kim on 2022/06/30. -// Copyright © 2022 Riiid Inc. All rights reserved. -// - -import SwiftUI - -extension View { - public func modified(@ViewBuilder modification: (Self) -> Modified) -> some View { - return modification(self) - } -} diff --git a/Sources/ComposableLogsSheetKit/LogsSheet.swift b/Sources/ComposableLogsSheetKit/LogsSheet.swift deleted file mode 100644 index eeb82c4..0000000 --- a/Sources/ComposableLogsSheetKit/LogsSheet.swift +++ /dev/null @@ -1,146 +0,0 @@ -// -// LogsSheet.swift -// -// Created by Jiyeon Song on 2022/06/17. -// Copyright © 2022 Riiid Inc. All rights reserved. -// - -import SPIndicator -import SwiftUI - -public struct LogsSheet: View { - @Environment(\.presentationMode) private var presentationMode: Binding - - private let logs: [ActionLog] - private let clearAction: () -> Void - - @State private var isAscending: Bool = false - @State private var showCopiedIndicator: Bool = false - @State private var searchText: String = "" - - public init(logs: [ActionLog], clearAction: @escaping () -> Void) { - self.logs = logs - self.clearAction = clearAction - } - - private var filteredLogs: [ActionLog] { - let sortedLogs: [ActionLog] = logs - .sorted(by: { - isAscending - ? $0.timeStamp < $1.timeStamp - : $0.timeStamp > $1.timeStamp - }) - return searchText.isEmpty - ? sortedLogs - : sortedLogs.filter { $0.message.localizedCaseInsensitiveContains(searchText) } - } - - public var body: some View { - NavigationView { - List { - ForEach(filteredLogs) { log in - Section(header: Text(log.timeStamp, formatter: dateFormatter)) { - ScrollView(.horizontal, showsIndicators: false) { - Button( - action: { - UIPasteboard.general.string = dateFormatter.string(from: log.timeStamp) + "\n" + log.message - showCopiedIndicator = true - }, - label: { - Text(log.message) - .font(Font.system(size: 12, design: .monospaced)) - .foregroundColor(.primary) - .multilineTextAlignment(.leading) - .padding() - } - ) - } - .listRowInsets(.init()) - } - } - } - .SPIndicator( - isPresent: $showCopiedIndicator, - title: "Copied to clipboard", - duration: 3.0 - ) - .listStyle(.grouped) - .navigationBarTitle("Logs for Debug") - .modified { - if #available(iOS 15.0, *) { - $0.searchable(text: $searchText) - } else { - $0 - } - } - .toolbar { - ToolbarItemGroup(placement: .bottomBar) { - Button( - action: { - UIPasteboard.general.string = logs - .map { dateFormatter.string(from: $0.timeStamp) + "\n" + $0.message } - .joined(separator: "\n") - showCopiedIndicator = true - }, - label: { - Text("Copy All") - } - ) - Spacer() - Button( - action: clearAction, - label: { - Text("Clear") - } - ) - } - ToolbarItem(placement: .automatic) { - Button( - action: { isAscending.toggle() }, - label: { - Image(systemName: isAscending ? "arrow.up.arrow.down.circle.fill" : "arrow.up.arrow.down.circle") - .renderingMode(.template) - .foregroundColor(.secondary) - } - ) - } - ToolbarItem(placement: .destructiveAction) { - Button( - action: { presentationMode.wrappedValue.dismiss() }, - label: { - Image(systemName: "xmark.circle.fill") - .renderingMode(.template) - .foregroundColor(.secondary) - } - ) - } - } - } - } -} - -private let dateFormatter: ISO8601DateFormatter = { - let formatter: ISO8601DateFormatter = .init() - formatter.timeZone = TimeZone.autoupdatingCurrent - return formatter -}() - -// MARK: Previewer - -struct LogsSheet_Previews: PreviewProvider { - static private let logsStub: [ActionLog] = [ - ActionLog(message: "stub action log"), - ActionLog(message: "stub action log"), - ActionLog(message: "stub action log") - ] - - static var previews: some View { - Group { - LogsSheet(logs: [], clearAction: {}) - .previewDisplayName("LogsSheet | empty") - - LogsSheet(logs: logsStub, clearAction: {}) - .previewDisplayName("LogsSheet | non empty") - } - } -} From 35d63b4f3fde4b7acb75abf2a6cdc00494cddef4 Mon Sep 17 00:00:00 2001 From: Yessen Date: Wed, 5 Oct 2022 23:58:31 +0900 Subject: [PATCH 08/12] :heavy_plus_sign: Added LogsSheetKit as dependency --- ...scheme => ComposableLogsSheetKit.xcscheme} | 24 +++++++++---------- ...e => ComposableLogsSheetKitTests.xcscheme} | 18 +++++++------- Package.resolved | 9 +++++++ Package.swift | 9 +++++-- .../LoggableState.swift | 1 + .../LoggableStateTests.swift | 1 + 6 files changed, 39 insertions(+), 23 deletions(-) rename .swiftpm/xcode/xcshareddata/xcschemes/{LogsSheetKit.xcscheme => ComposableLogsSheetKit.xcscheme} (79%) rename .swiftpm/xcode/xcshareddata/xcschemes/{LogsSheetKitTests.xcscheme => ComposableLogsSheetKitTests.xcscheme} (80%) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKit.xcscheme similarity index 79% rename from .swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKit.xcscheme index 2445259..222c885 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKit.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKit.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -28,9 +28,9 @@ buildForAnalyzing = "YES"> @@ -46,9 +46,9 @@ skipped = "NO"> @@ -74,9 +74,9 @@ diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKitTests.xcscheme similarity index 80% rename from .swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKitTests.xcscheme index e541887..7d90eee 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/LogsSheetKitTests.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/ComposableLogsSheetKitTests.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "NO"> @@ -32,9 +32,9 @@ skipped = "NO"> @@ -60,9 +60,9 @@ diff --git a/Package.resolved b/Package.resolved index 7c35059..77e5e4c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,6 +9,15 @@ "version" : "0.8.0" } }, + { + "identity" : "logssheetkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/riiid/LogsSheetKit", + "state" : { + "revision" : "5bb7cc405d718e86f9362e6a335230e2e295801b", + "version" : "0.9.0" + } + }, { "identity" : "spindicator", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index a117968..cb31a02 100644 --- a/Package.swift +++ b/Package.swift @@ -14,17 +14,22 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/ivanvorobei/SPIndicator", .upToNextMajor(from: "1.6.0")), - .package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMajor(from: "0.40.0")) + .package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMajor(from: "0.40.0")), + .package(url: "https://github.com/riiid/LogsSheetKit", .upToNextMajor(from: "0.9.0")) ], targets: [ .target( name: "ComposableLogsSheetKit", dependencies: [ "SPIndicator", + "LogsSheetKit", .product(name: "ComposableArchitecture", package: "swift-composable-architecture") ]), .testTarget( name: "ComposableLogsSheetKitTests", - dependencies: ["ComposableLogsSheetKit"]), + dependencies: [ + "ComposableLogsSheetKit", + "LogsSheetKit" + ]), ] ) diff --git a/Sources/ComposableLogsSheetKit/LoggableState.swift b/Sources/ComposableLogsSheetKit/LoggableState.swift index 2f3a89e..e2a66f4 100644 --- a/Sources/ComposableLogsSheetKit/LoggableState.swift +++ b/Sources/ComposableLogsSheetKit/LoggableState.swift @@ -7,6 +7,7 @@ // import Foundation +import LogsSheetKit public protocol LoggableState: Equatable { var logs: [ActionLog] { get set } diff --git a/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift b/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift index 8d6cfc4..d3b5daa 100644 --- a/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift +++ b/Tests/ComposableLogsSheetKitTests/LoggableStateTests.swift @@ -7,6 +7,7 @@ // import XCTest +import LogsSheetKit @testable import ComposableLogsSheetKit final class LoggableStateTests: XCTestCase { From 44c007b4450d78864db1035a63ac97e4bd856d06 Mon Sep 17 00:00:00 2001 From: Yessen Date: Thu, 6 Oct 2022 00:01:55 +0900 Subject: [PATCH 09/12] :recycle: Add isDebug to log() --- .../Extensions/TCA/Reducer+Log.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift index 3e3dbce..cfa4e44 100644 --- a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift +++ b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -10,11 +10,11 @@ import Foundation import ComposableArchitecture extension Reducer where State: LoggableState { - public func log() -> Self { + public func log(isDebug: Bool) -> Self { .init { state, action, environment in - #if DEBUG || STG - state.logs.append(.init(message: "\(action)")) - #endif + if isDebug { + state.logs.append(.init(message: "\(action)")) + } return self.run(&state, action, environment) } } From a786f195bc678d576c2b8e11c67b4970d46d1977 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Thu, 6 Oct 2022 10:48:43 +0900 Subject: [PATCH 10/12] :sparkles: Added custom message logger Added function documentation as well. --- .../Extensions/TCA/Reducer+Log.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift index cfa4e44..e469803 100644 --- a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift +++ b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -10,6 +10,9 @@ import Foundation import ComposableArchitecture extension Reducer where State: LoggableState { + /// 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 { .init { state, action, environment in if isDebug { @@ -18,4 +21,17 @@ extension Reducer where State: LoggableState { 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: String) -> Self { + .init { state, action, environment in + if isDebug { + state.logs.append(.init(message: message)) + } + return self.run(&state, action, environment) + } + } } From 8cbaf3990eeb81861e7ec36cd5908c6b592cfc05 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Thu, 6 Oct 2022 13:12:55 +0900 Subject: [PATCH 11/12] :recycle: Add Action to message in custom log --- .../Extensions/TCA/Reducer+Log.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift index e469803..627025f 100644 --- a/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift +++ b/Sources/ComposableLogsSheetKit/Extensions/TCA/Reducer+Log.swift @@ -26,10 +26,13 @@ extension Reducer where State: LoggableState { /// - Parameters: /// - isDebug: is debug configuration on /// - message: custom log message - public func log(isDebug: Bool, with message: String) -> Self { + public func log( + isDebug: Bool, + with message: @escaping ((Action) -> String) + ) -> Self { .init { state, action, environment in if isDebug { - state.logs.append(.init(message: message)) + state.logs.append(.init(message: message(action))) } return self.run(&state, action, environment) } From e9245279fd73a3e9c7f941fb1e795ce8bbc0de51 Mon Sep 17 00:00:00 2001 From: yermukhanbet Date: Thu, 6 Oct 2022 13:20:41 +0900 Subject: [PATCH 12/12] :heavy_minus_sign: Remove SPIndicator --- Package.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Package.swift b/Package.swift index cb31a02..17cd3ab 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,6 @@ let package = Package( targets: ["ComposableLogsSheetKit"]), ], dependencies: [ - .package(url: "https://github.com/ivanvorobei/SPIndicator", .upToNextMajor(from: "1.6.0")), .package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMajor(from: "0.40.0")), .package(url: "https://github.com/riiid/LogsSheetKit", .upToNextMajor(from: "0.9.0")) ], @@ -21,7 +20,6 @@ let package = Package( .target( name: "ComposableLogsSheetKit", dependencies: [ - "SPIndicator", "LogsSheetKit", .product(name: "ComposableArchitecture", package: "swift-composable-architecture") ]),