Skip to content

Commit

Permalink
Merge pull request #57 from SwiftGraphs/zl/fix-concurrency
Browse files Browse the repository at this point in the history
Zero concurrency warnings
  • Loading branch information
li3zhen1 authored Aug 25, 2024
2 parents cc59703 + 23f7abc commit 5c24e87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
24 changes: 4 additions & 20 deletions Sources/Grape/Modifiers/GraphForegroundScale.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
import SwiftUI

@usableFromInline
enum GrapeEnvironment { }

@available(*, unavailable)
extension AnyHashable: @unchecked Sendable { }

extension GrapeEnvironment {
@usableFromInline
struct GraphForegroundScale: EnvironmentKey, Sendable {
@usableFromInline
static let defaultValue: [AnyHashable: GraphicsContext.Shading] = [:]
}
}

extension EnvironmentValues {
@inlinable
var graphForegroundScaleEnvironment: GrapeEnvironment.GraphForegroundScale.Value {
get { self[GrapeEnvironment.GraphForegroundScale.self] }
set { self[GrapeEnvironment.GraphForegroundScale.self] = newValue }
}
@usableFromInline
@Entry
var graphForegroundScaleEnvironment: [AnyHashable: GraphicsContext.Shading] = [:]
}

@usableFromInline
struct GraphEnvironmentViewModifier: ViewModifier {

@usableFromInline
let colorScale: Dictionary<AnyHashable, GraphicsContext.Shading>
let colorScale: [AnyHashable: GraphicsContext.Shading]

@inlinable
init<DataValue, S>(_ mapping: KeyValuePairs<DataValue, S>) where S: ShapeStyle, DataValue: Hashable {
Expand Down
19 changes: 4 additions & 15 deletions Sources/Grape/Views/ForceDirectedGraphModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Foundation
import Observation
import SwiftUI

// @Observable
@MainActor
public final class ForceDirectedGraphModel<Content: GraphContent> {

Expand All @@ -21,17 +20,6 @@ public final class ForceDirectedGraphModel<Content: GraphContent> {
@usableFromInline
var simulationContext: SimulationContext<NodeID>

// @usableFromInline
// internal var _modelTransform: ViewportTransform
// {
// didSet {
// stateMixinRef.modelTransform = modelTransform
// }
// }

// @usableFromInline
// internal var _modelTransformExtenalBinding: Binding<ViewportTransform>

@inlinable
internal var modelTransform: ViewportTransform {
// @storageRestrictions(initializes: _modelTransform)
Expand Down Expand Up @@ -128,7 +116,7 @@ public final class ForceDirectedGraphModel<Content: GraphContent> {
let ticksPerSecond: Double

@usableFromInline
@MainActor
// @MainActor
var scheduledTimer: Timer? = nil

@usableFromInline
Expand Down Expand Up @@ -268,8 +256,9 @@ public final class ForceDirectedGraphModel<Content: GraphContent> {

@inlinable
deinit {
self.scheduledTimer?.invalidate()
self.scheduledTimer = nil
_ = MainActor.assumeIsolated {
scheduledTimer?.invalidate()
}
}

@usableFromInline
Expand Down

0 comments on commit 5c24e87

Please sign in to comment.