feat: refresh objects

This commit is contained in:
dscyrescotti
2024-06-10 22:53:29 +07:00
parent 7d52733d5d
commit 2e254dc4af
2 changed files with 8 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ final class GraphicContext: @unchecked Sendable {
withPersistence(\.backgroundContext) { [stroke = deletedStroke] context in
stroke?.stroke(as: PenStroke.self)?.object?.graphicContext = nil
try context.saveIfNeeded()
context.refreshAllObjects()
}
case .eraser:
guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else { return }
@@ -64,6 +65,8 @@ final class GraphicContext: @unchecked Sendable {
penStroke.object?.erasers.remove(object)
}
}
try context.saveIfNeeded()
context.refreshAllObjects()
}
}
previousStroke = nil
@@ -82,6 +85,7 @@ final class GraphicContext: @unchecked Sendable {
withPersistence(\.backgroundContext) { [weak self, penStroke] context in
penStroke.object?.graphicContext = self?.object
try context.saveIfNeeded()
context.refreshAllObjects()
}
case .eraser:
guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else {
@@ -97,6 +101,7 @@ final class GraphicContext: @unchecked Sendable {
}
}
try context.saveIfNeeded()
context.refreshAllObjects()
}
}
previousStroke = nil
@@ -120,12 +125,14 @@ extension GraphicContext {
withPersistenceSync(\.newBackgroundContext) { [_stroke] context in
guard let stroke = try? context.existingObject(with: id) as? StrokeObject else { return }
_stroke.loadQuads(from: stroke, with: self)
context.refreshAllObjects()
}
}
} else {
withPersistence(\.backgroundContext) { [weak self] context in
guard let self else { return }
_stroke.loadQuads(with: self)
context.refreshAllObjects()
}
}
}

View File

@@ -69,6 +69,7 @@ extension Canvas {
func loadStrokes(_ bounds: CGRect) {
withPersistence(\.backgroundContext) { [weak self, bounds] context in
self?.graphicContext.loadQuads(bounds, on: context)
context.refreshAllObjects()
}
}
}