Преглед на файлове

Got rid of static router in Application coordinator

Pavel Yurchenko преди 1 година
родител
ревизия
2600f38d82

+ 0 - 8
CoordinatorSUIExamples.xcodeproj/project.pbxproj

@@ -35,19 +35,11 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
-		060F7D0A2CF8520A005B0507 /* Frameworks */ = {
-			isa = PBXGroup;
-			children = (
-			);
-			name = Frameworks;
-			sourceTree = "<group>";
-		};
 		06C5BF752C707D2C006896A8 = {
 			isa = PBXGroup;
 			children = (
 				06B1064E2CF84E210047B090 /* CoordinatorSUI */,
 				06C5BF802C707D2C006896A8 /* SUIExamples */,
-				060F7D0A2CF8520A005B0507 /* Frameworks */,
 				06C5BF7F2C707D2C006896A8 /* Products */,
 			);
 			sourceTree = "<group>";

+ 0 - 7
SUIExamples/Application/ApplicationCoordinator.swift

@@ -10,13 +10,6 @@ import SwiftUI
 
 final class ApplicationCoordinator: BaseCoordinator {
 
-    static var rootRouter = Router()
-
-    override init() {
-        super.init()
-        self.currentRouter = Self.rootRouter
-    }
-
     func run() -> some View {
         runMainFlow()
     }

+ 4 - 2
SUIExamples/Application/SUIExamplesApp.swift

@@ -11,8 +11,10 @@ import SwiftUI
 @main
 struct SUIExamplesApp: App {
 
-    private let applicationCoordinator = ApplicationCoordinator()
-    @StateObject private var router: Router = ApplicationCoordinator.rootRouter
+    private static let coordinator = ApplicationCoordinator()
+
+    private let applicationCoordinator = coordinator
+    @StateObject private var router: Router = coordinator.currentRouter
 
     var body: some Scene {
         WindowGroup {

+ 4 - 6
SUIExamples/Modules/Cart/CartBuilder.swift

@@ -12,11 +12,9 @@ struct CartBuilder {
     typealias Output = CartVM.Output
 
     func build(with output: Output) -> some View {
-        CartView()
-            .environment(
-                CartVM(
-                    output: output
-                )
-            )
+        let vm = CartVM(
+            output: output
+        )
+        return CartView().environment(vm)
     }
 }

+ 4 - 6
SUIExamples/Modules/Feedback/FeedbackBuilder.swift

@@ -12,11 +12,9 @@ struct FeedbackBuilder {
     typealias Output = FeedbackVM.Output
 
     func build(with output: Output) -> some View {
-        FeedbackView()
-            .environment(
-                FeedbackVM(
-                    output: output
-                )
-            )
+        let vm = FeedbackVM(
+            output: output
+        )
+        return FeedbackView().environment(vm)
     }
 }

+ 4 - 6
SUIExamples/Modules/Main/MainBuilder.swift

@@ -12,11 +12,9 @@ struct MainBuilder {
     typealias Output = MainVM.Output
 
     func build(with output: Output) -> some View {
-        MainView()
-            .environment(
-                MainVM(
-                    output: output
-                )
-            )
+        let vm = MainVM(
+            output: output
+        )
+        return MainView().environment(vm)
     }
 }

+ 5 - 7
SUIExamples/Modules/Product/ProductBuilder.swift

@@ -13,12 +13,10 @@ struct ProductBuilder {
     typealias Output = ProductVM.Output
 
     func build(with input: Input, output: Output) -> some View {
-        ProductView()
-            .environment(
-                ProductVM(
-                    input: input,
-                    output: output
-                )
-            )
+        let vm = ProductVM(
+            input: input,
+            output: output
+        )
+        return ProductView().environment(vm)
     }
 }

+ 7 - 4
SUIExamples/Modules/Product/ProductVM.swift

@@ -20,15 +20,18 @@ final class ProductVM {
     }
 
     let output: Output
-
-    var productId: Int {
-        input.id
-    }
+    var objectId: Int
 
     private let input: Input
 
     init(input: Input, output: Output) {
         self.input = input
         self.output = output
+
+        self.objectId = input.id
+
+        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
+            self.objectId = input.id + 5
+        }
     }
 }

+ 1 - 1
SUIExamples/Modules/Product/ProductView.swift

@@ -14,7 +14,7 @@ struct ProductView: View {
         VStack {
             Text("Product")
             Spacer()
-            Text("#\(vm.productId)")
+            Text("#\(vm.objectId)")
             Spacer()
             Button("Products") {
                 vm.output.onProducts?()

+ 4 - 6
SUIExamples/Modules/Products/ProductsBuilder.swift

@@ -12,11 +12,9 @@ struct ProductsBuilder {
     typealias Output = ProductsVM.Output
 
     func build(with output: Output) -> some View {
-        ProductsView()
-            .environment(
-                ProductsVM(
-                    output: output
-                )
-            )
+        let vm = ProductsVM(
+            output: output
+        )
+        return ProductsView().environment(vm)
     }
 }