meta/Sources/Model/Data Flow/StateManager.swift
david-swift 6c5769517f
All checks were successful
Deploy Docs / publish (push) Successful in 47s
SwiftLint / SwiftLint (push) Successful in 1m0s
Move to backend-specific app ID logic
2024-10-08 12:24:13 +02:00

37 lines
1019 B
Swift

//
// StateManager.swift
// Meta
//
// Created by david-swift on 21.06.24.
//
import Foundation
/// This type manages view updates.
public enum StateManager {
/// Whether to block updates in general.
public static var blockUpdates = false
/// The functions handling view updates.
static var updateHandlers: [(Bool) -> Void] = []
/// Update all of the views.
/// - Parameter force: Whether to force all views to update.
///
/// Nothing happens if ``StateManager/blockUpdates`` is true.
public static func updateViews(force: Bool = false) {
if !blockUpdates {
for handler in updateHandlers {
handler(force)
}
}
}
/// Add a handler that is called when the user interface should update.
/// - Parameter handler: The handler. The parameter defines whether the whole UI should be force updated.
static func addUpdateHandler(handler: @escaping (Bool) -> Void) {
updateHandlers.append(handler)
}
}