Skip to content

Commit

Permalink
Add GraphDelegate and update App related
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Feb 25, 2024
1 parent bc0b3c7 commit b4f1042
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
13 changes: 13 additions & 0 deletions Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift
Original file line number Diff line number Diff line change
@@ -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<V>(body: (GraphHost) -> V) -> V
func graphDidChange()
func preferencesDidChange()
}
43 changes: 38 additions & 5 deletions Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<PreferenceList>
// 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
Expand All @@ -40,6 +69,10 @@ extension GraphHost {
@Attribute
var transaction: Transaction
var inputs: _GraphInputs

init() {
fatalError("TODO")
}
}
}

Expand Down

0 comments on commit b4f1042

Please sign in to comment.