Skip to content

Commit 95ba079

Browse files
committed
Track bridge observation mutation reads
1 parent 367a9c4 commit 95ba079

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let package = Package(
1212
dependencies: [
1313
.package(url: "https://source.skip.tools/skip.git", from: "1.2.34"),
1414
.package(url: "https://source.skip.tools/skip-foundation.git", from: "1.3.1"),
15+
.package(url: "https://source.skip.tools/skip-model.git", from: "1.7.2"),
1516
.package(url: "https://source.skip.tools/swift-jni.git", "0.0.0"..<"2.0.0"),
1617
.package(url: "https://source.skip.tools/skip-bridge.git", "0.0.0"..<"2.0.0"),
1718
.package(url: "https://source.skip.tools/swift-android-native.git", from: "1.4.1")
@@ -21,6 +22,7 @@ let package = Package(
2122
.product(name: "SkipBridge", package: "skip-bridge"),
2223
.product(name: "SwiftJNI", package: "swift-jni"),
2324
.product(name: "SkipFoundation", package: "skip-foundation"),
25+
.product(name: "SkipModel", package: "skip-model"),
2426
.product(name: "AndroidNative", package: "swift-android-native", condition: .when(platforms: [.android])),
2527
], plugins: [.plugin(name: "skipstone", package: "skip")]),
2628

Sources/SkipAndroidBridge/Observation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#if SKIP_BRIDGE
44

55
import SwiftJNI
6+
import SkipModel
67
#if canImport(FoundationEssentials)
78
import FoundationEssentials
89
#else
@@ -67,11 +68,18 @@ private final class BridgeObservationSupport: @unchecked Sendable {
6768

6869
public func access<Subject, Member>(_ subject: Subject, keyPath: KeyPath<Subject, Member>) {
6970
let index = Java_init(forKeyPath: keyPath)
71+
lock.wait()
72+
let transaction = lastMutationTransactions[index]
73+
lock.signal()
74+
StateTracking.recordMutationRead(transaction)
7075
Java_access(index)
7176
}
7277

7378
public func willSet<Subject, Member>(_ subject: Subject, keyPath: KeyPath<Subject, Member>) {
7479
let index = Java_init(forKeyPath: keyPath)
80+
lock.wait()
81+
lastMutationTransactions[index] = StateTracking.currentMutationTransaction
82+
lock.signal()
7583
Java_update(index)
7684
}
7785

@@ -135,6 +143,7 @@ private final class BridgeObservationSupport: @unchecked Sendable {
135143

136144
private let lock = DispatchSemaphore(value: 1)
137145
private var indexes: [AnyKeyPath: Int] = [:]
146+
private var lastMutationTransactions: [Int: StateMutationTransaction] = [:]
138147

139148
private func index(forKeyPath keyPath: AnyKeyPath) -> Int {
140149
if let index = indexes[keyPath] {

0 commit comments

Comments
 (0)