Skip to content

Commit

Permalink
feature/graphhost (#44)
Browse files Browse the repository at this point in the history
* Update GraphHost inheritable methods

* Update graphInvalidation implementation

* Update GraphHost implementation

* Add currentHost

* Update OpenGraph depedency

* Update GraphHost

* Fix isUpdateing setter compile issue

* Add flushTransactions and continueTransaction

* Update missing GraphHost interface

* Fix Linux platform build issue
  • Loading branch information
Kyle-Ye committed Mar 9, 2024
1 parent fe1f99e commit 02d8ca4
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "10eb096bfdefd73bb50df410b87602208bcc06c1"
"revision" : "2435a0a02b3ab3b97799a8f387284686fe9e6a7a"
}
},
{
Expand Down
14 changes: 14 additions & 0 deletions Scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/zsh

# A `realpath` alternative using the default C implementation.
filepath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

OPENSWIFTUI_ROOT="$(dirname $(dirname $(filepath $0)))"

cd $OPENSWIFTUI_ROOT

export OPENSWIFTUI_SWIFT_TESTING=0
export OPENGRAPH_SWIFT_TESTING=0
swift build
14 changes: 14 additions & 0 deletions Sources/OpenSwiftUI/Core/Attribute/InvalidatableAttribute.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// InvalidatableAttribute.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

internal import OpenGraphShims

// TODO: PlatformViewChild in _A513612C07DFA438E70B9FA90719B40D

protocol InvalidatableAttribute: _AttributeBody {
static func willInvalidate(attribute: OGAttribute)
}
13 changes: 13 additions & 0 deletions Sources/OpenSwiftUI/Core/Attribute/RemovableAttribute.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// RemovableAttribute.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

internal import OpenGraphShims

protocol RemovableAttribute: _AttributeBody {
static func willRemove(attribute: OGAttribute)
static func didReinsert(attribute: OGAttribute)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ struct ObservableObjectLocation<Root, Value>: Location where Root: ObservableObj
base[keyPath: keyPath] = value
}
}

extension ObservableObjectLocation: TransactionHostProvider {
// TODO
var mutationHost: GraphHost? { nil }
}
5 changes: 5 additions & 0 deletions Sources/OpenSwiftUI/Core/Graph/Extensions/OGGraph.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
internal import OpenGraphShims

extension OGGraph {

}
38 changes: 38 additions & 0 deletions Sources/OpenSwiftUI/Core/Graph/Extensions/OGSubgraph.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
internal import OpenGraphShims

extension OGSubgraph {
func willRemove() {
#if canImport(Darwin)
OGSubgraph.apply(self, flags: .removable) { attribute in
let type = attribute._bodyType
if let removableType = type as? RemovableAttribute.Type {
removableType.willRemove(attribute: attribute)
}
}
#endif
}

func didReinsert() {
#if canImport(Darwin)
OGSubgraph.apply(self, flags: .removable) { attribute in
let type = attribute._bodyType
if let removableType = type as? RemovableAttribute.Type {
removableType.didReinsert(attribute: attribute)
}
}
#endif
}

func willInvalidate(isInserted: Bool) {
#if canImport(Darwin)
OGSubgraph.apply(self, flags: isInserted ? [.removable, .invalidatable] : [.invalidatable]) { attribute in
let type = attribute._bodyType
if let invalidatableType = type as? InvalidatableAttribute.Type {
invalidatableType.willInvalidate(attribute: attribute)
} else if isInserted, let removableType = type as? RemovableAttribute.Type {
removableType.willRemove(attribute: attribute)
}
}
#endif
}
}
Loading

0 comments on commit 02d8ca4

Please sign in to comment.