vector-im/element-x-ios/issues/53 - Adopt MainActors, dispatch heavy operations do detached tasks and ensure combine publisher call back on the right queue

This commit is contained in:
Stefan Ceriu
2022-05-25 13:28:19 +03:00
committed by Stefan Ceriu
parent dde7786152
commit f5890b68a2
29 changed files with 100 additions and 90 deletions
+1
View File
@@ -19,6 +19,7 @@ import UIKit
/// Protocol describing a [Coordinator](http://khanlou.com/2015/10/coordinators-redux/).
/// Coordinators are the objects which control the navigation flow of the application.
/// It helps to isolate and reuse view controllers and pass dependencies down the navigation hierarchy.
@MainActor
protocol Coordinator: AnyObject {
/// Starts job of the coordinator.
@@ -17,6 +17,7 @@
import UIKit
/// `NavigationRouterStoreProtocol` describes a structure that enables to get a NavigationRouter from a UINavigationController instance.
@MainActor
protocol NavigationRouterStoreProtocol {
/// Gets the existing navigation router for the supplied controller, creating a new one if it doesn't yet exist.
@@ -18,6 +18,7 @@ import UIKit
/// Protocol describing a router that wraps a UINavigationController and add convenient completion handlers. Completions are called when a Presentable is removed.
/// Routers are used to be passed between coordinators. They handles only `physical` navigation.
@MainActor
protocol NavigationRouterType: AnyObject, Presentable {
/// Present modally a view controller on the navigation controller
@@ -17,6 +17,7 @@
import UIKit
/// Protocol used to pass UIViewControllers to routers
@MainActor
protocol Presentable {
func toPresentable() -> UIViewController
}
@@ -18,6 +18,7 @@ import UIKit
/// Protocol describing a router that wraps the root navigation of the application.
/// Routers are used to be passed between coordinators. They handles only `physical` navigation.
@MainActor
protocol RootRouterType: AnyObject {
/// Update the root view controller
@@ -30,6 +30,7 @@ import Combine
/// It provides a nice layer of consistency and also safety. As we are not passing the `ViewModel` to the view directly, shortcuts/hacks
/// can't be made into the `ViewModel`.
@dynamicMemberLookup
@MainActor
class ViewModelContext<ViewState: BindableState, ViewAction>: ObservableObject {
// MARK: - Properties
@@ -70,6 +71,7 @@ class ViewModelContext<ViewState: BindableState, ViewAction>: ObservableObject {
/// a specific portion of state that can be safely bound to.
/// If we decide to add more features to our state management (like doing state processing off the main thread)
/// we can do it in this centralised place.
@MainActor
class StateStoreViewModel<State: BindableState, ViewAction> {
typealias Context = ViewModelContext<State, ViewAction>