//
//  PhoneRootModuleFactory.swift
//  Eurofurence
//
//  Created by Thomas Sherwood on 06/11/2017.
//  Copyright © 2017 Eurofurence. All rights reserved.
//

struct PhoneRootModuleFactory: RootModuleProviding {

    var app: EurofurenceApplicationProtocol

    func makeRootModule(_ delegate: RootModuleDelegate) {
        let actions: [EurofurenceDataStoreState : () -> Void] = [
            .absent: delegate.userNeedsToWitnessTutorial,
            .stale: delegate.storeShouldBePreloaded,
            .available: delegate.rootModuleDidDetermineRootModuleShouldBePresented
        ]

        app.resolveDataStoreState { actions[$0]!() }
    }

}

//
//  PhoneRootModuleFactory.swift
//  Eurofurence
//
//  Created by Thomas Sherwood on 06/11/2017.
//  Copyright © 2017 Eurofurence. All rights reserved.
//

struct PhoneRootModuleFactory: RootModuleProviding {

    var app: EurofurenceApplicationProtocol

    func makeRootModule(_ delegate: RootModuleDelegate) {
        app.resolveDataStoreState { (state) in
            switch state {
            case .absent:
                delegate.userNeedsToWitnessTutorial()

            case .stale:
                delegate.storeShouldBePreloaded()

            case .available:
                delegate.rootModuleDidDetermineRootModuleShouldBePresented()
            }
        }
    }

}

--- 
+++ 
@@ -11,18 +11,13 @@
     var app: EurofurenceApplicationProtocol
 
     func makeRootModule(_ delegate: RootModuleDelegate) {
-        app.resolveDataStoreState { (state) in
-            switch state {
-            case .absent:
-                delegate.userNeedsToWitnessTutorial()
+        let actions: [EurofurenceDataStoreState : () -> Void] = [
+            .absent: delegate.userNeedsToWitnessTutorial,
+            .stale: delegate.storeShouldBePreloaded,
+            .available: delegate.rootModuleDidDetermineRootModuleShouldBePresented
+        ]
 
-            case .stale:
-                delegate.storeShouldBePreloaded()
-
-            case .available:
-                delegate.rootModuleDidDetermineRootModuleShouldBePresented()
-            }
-        }
+        app.resolveDataStoreState { actions[$0]!() }
     }
 
 }
Refactor root module to remove switch statement
