-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppDelegate.swift
60 lines (46 loc) · 1.71 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// AppDelegate.swift
// RealWorldReSwift
//
// Created by Tobias Ottenweller on 25.03.18.
// Copyright © 2018 Tobias Ottenweller. All rights reserved.
//
import CoreLocation
import UIKit
import ReSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let placesService: PlacesServing
private let appStore: AppStore
private let locationEmitter: LocationEmitter
private let locationObserver: LocationObserver
override init() {
let locationManager = CLLocationManager()
placesService = PlacesService(
locale: .current,
apiKey: "<key here>",
fetcher: NetworkFetcher(session: .shared, decoder: JSONDecoder())
)
appStore = AppStore(
reducer: appReducer,
state: nil,
middleware: [
createMiddleware(fetchPlaces(service: placesService)),
createMiddleware(requestAuthorization(locationManager: locationManager)),
createMiddleware(startMonitoring(locationManager: locationManager))
]
)
locationEmitter = LocationEmitter(locationManager: locationManager, store: appStore)
locationObserver = LocationObserver(store: appStore)
super.init()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let viewController = window?.rootViewController as! ViewController
viewController.store = appStore
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
appStore.dispatch(ApplicationDidBecomeActiveAction())
}
}