From b4f10420ce30ff398b11be5232de56e34333bbd7 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 26 Feb 2024 02:10:26 +0800 Subject: [PATCH] Add GraphDelegate and update App related --- .../AppOrganization/Graph/AppGraph.swift | 10 ++++- .../TODO/OpenSwiftUIApplication.swift | 4 +- .../Internal/Graph/GraphDelegate.swift | 13 ++++++ .../Internal/Graph/GraphHost.swift | 43 ++++++++++++++++--- 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift diff --git a/Sources/OpenSwiftUI/AppStructure/AppOrganization/Graph/AppGraph.swift b/Sources/OpenSwiftUI/AppStructure/AppOrganization/Graph/AppGraph.swift index e0d489d..e3931b6 100644 --- a/Sources/OpenSwiftUI/AppStructure/AppOrganization/Graph/AppGraph.swift +++ b/Sources/OpenSwiftUI/AppStructure/AppOrganization/Graph/AppGraph.swift @@ -35,8 +35,16 @@ final class AppGraph: GraphHost { }() var didCollectLaunchProfile: Bool = false + + // TODO + init(app: some App) { + let data = GraphHost.Data() + super.init(data: data) + } - init(app _: some App) {} + // MARK: - Override Methods + + // MARK: - Profile related func extendedLaunchTestName() -> String? { nil } diff --git a/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/OpenSwiftUIApplication.swift b/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/OpenSwiftUIApplication.swift index 54dc1d8..d34fd4a 100644 --- a/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/OpenSwiftUIApplication.swift +++ b/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/OpenSwiftUIApplication.swift @@ -32,12 +32,10 @@ import Foundation #endif func runApp(_ app: some App) -> Never { - #if canImport(Darwin) let graph = AppGraph(app: app) graph.startProfilingIfNecessary() -// graph.instantiate() + graph.instantiate() AppGraph.shared = graph - #endif KitRendererCommon() } diff --git a/Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift b/Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift new file mode 100644 index 0000000..0ab76db --- /dev/null +++ b/Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift @@ -0,0 +1,13 @@ +// +// GraphDelegate.swift +// OpenSwiftUI +// +// Created by Kyle on 2024/2/26. +// Lastest Version: iOS 15.5 +// Status: Complete + +protocol GraphDelegate: AnyObject { + func updateGraph(body: (GraphHost) -> V) -> V + func graphDidChange() + func preferencesDidChange() +} diff --git a/Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift b/Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift index fab39cf..476179e 100644 --- a/Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift +++ b/Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift @@ -3,21 +3,50 @@ internal import OpenGraphShims class GraphHost { - -// var data: Data -// var isInstantiated: Swift.Bool + var data: Data + var isInstantiated: Bool // var hostPreferenceValues: OptionalAttribute // var lastHostPreferencesSeed: VersionSeed -// var pendingTransactions: [SwiftUI.(AsyncTransaction in _30C09FF16BC95EC5173809B57186CAC3)] +// var pendingTransactions: [AsyncTransaction] // var inTransaction: Bool // var continuations: [() -> ()] // var mayDeferUpdate: Bool // var removedState: RemovedState + // FIXME static var isUpdating = false + + // private static let shared = OGGraphCreate() + // MARK: - non final methods -// private static let shared = OGGraphCreate() + init(data: Data) { + self.data = data + isInstantiated = false + // TODO + } + + func invalidate() { + // TODO + } + + var graphDelegate: GraphDelegate? { nil } + var parentHost: GraphHost? { nil } + func instantiateOutputs() {} + func uninstantiateOutputs() {} + func timeDidChange() {} + func isHiddenForReuseDidChange() {} + + // MARK: - final methods + + final func instantiate() { + guard !isInstantiated else { + return + } + graphDelegate?.updateGraph { _ in } + instantiateOutputs() + isInstantiated = true + } } // MARK: - GraphHost.Data @@ -40,6 +69,10 @@ extension GraphHost { @Attribute var transaction: Transaction var inputs: _GraphInputs + + init() { + fatalError("TODO") + } } }