This file contains hidden or 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
func fetchPlaces(action: Action, context: MiddlewareContext<AppState>) -> Action? { | |
// create places service | |
// perform network request | |
// dispatch set places action on success | |
} |
This file contains hidden or 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
func create(Dependency) -> Middleware |
This file contains hidden or 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
func fetchPlaces(service: PlacesServing) -> SimpleMiddleware<AppState> { | |
return { (action, context) in | |
guard | |
let placesAction = action as? PlacesAction, | |
case .fetch = placesAction | |
else { | |
return action | |
} |
This file contains hidden or 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
let placesService = PlacesService( | |
locale: .current, | |
apiKey: "<key here>", | |
fetcher: NetworkFetcher(session: .shared, decoder: JSONDecoder()) | |
) | |
let appStore = AppStore( | |
reducer: appReducer, | |
state: nil, | |
middleware: [ |
This file contains hidden or 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
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
private let placesService: PlacesServing | |
private let appStore: AppStore | |
override init() { |
This file contains hidden or 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
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
let viewController = window?.rootViewController as! ViewController | |
viewController.store = appStore | |
return true | |
} |
This file contains hidden or 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
// Loadable.swift | |
enum Loadable<T> { | |
case initial | |
case loading | |
case value(T) | |
case error(Error) | |
} | |
// AppState.swift | |
struct AppState: StateType { |
This file contains hidden or 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
final class LocationEmitter: NSObject { | |
private let locationManager: CLLocationManager | |
private let store: AppStore | |
init(locationManager: CLLocationManager, store: AppStore) { | |
[…] | |
locationManager.delegate = self | |
[…] | |
} |
This file contains hidden or 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
class AppDelegate: UIResponder, UIApplicationDelegate { | |
[…] | |
private let locationEmitter: LocationEmitter | |
override init() { | |
[…] | |
locationEmitter = LocationEmitter(locationManager: CLLocationManager(), store: appStore) | |
[…] |
This file contains hidden or 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
extension ViewController: StoreSubscriber { | |
typealias StoreSubscriberStateType = AppState | |
func newState(state: AppState) { | |
[…] | |
authorizationNotDeterminedView.isHidden = state.authorizationStatus != .notDetermined | |
authorizationDeniedView.isHidden = (state.authorizationStatus == .authorizedAlways) || (state.authorizationStatus == .authorizedWhenInUse) | |
} | |
} |