mirror of
https://github.com/garrytan/gstack.git
synced 2026-08-31 10:20:42 +02:00
fix(ios-qa): generate app-owned bridge accessors deterministically
This commit is contained in:
@@ -1,32 +1,22 @@
|
||||
// Canonical app state for the fixture. Every snapshot-eligible field is
|
||||
// marked with the @Snapshotable property wrapper that the codegen tool
|
||||
// detects via attribute scan.
|
||||
//
|
||||
// Note: we DON'T use @Observable here because the macro expansion converts
|
||||
// stored properties into computed ones, which the @Snapshotable wrapper
|
||||
// can't apply to. In production apps that need both observability AND
|
||||
// snapshotting, the right pattern is:
|
||||
// - Use ObservableObject + @Published (older API), or
|
||||
// - Hold all @Snapshotable state in a nested struct + replace it
|
||||
// wholesale on restore so SwiftUI sees a single change notification
|
||||
// (the canonical-state-struct atomicity strategy from the plan).
|
||||
// Canonical observable app state for the fixture. Snapshot eligibility is a
|
||||
// generator-only source marker, not a property wrapper, so it composes with
|
||||
// Observation's @Observable macro.
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
public final class FixtureAppState {
|
||||
@Snapshotable public var isLoggedIn: Bool = false
|
||||
@Snapshotable public var username: String = ""
|
||||
@Snapshotable public var tapCounter: Int = 0
|
||||
@Observable
|
||||
final class FixtureAppState {
|
||||
// @Snapshotable
|
||||
var isLoggedIn: Bool = false
|
||||
// @Snapshotable
|
||||
var username: String = ""
|
||||
// @Snapshotable
|
||||
var tapCounter: Int = 0
|
||||
// @Snapshotable
|
||||
var nickname: String? = nil
|
||||
/// Not snapshotted — ephemeral cache that should never leak via /state/snapshot.
|
||||
public var ephemeralCache: [String: String] = [:]
|
||||
var ephemeralCache: [String: String] = [:]
|
||||
|
||||
public init() {}
|
||||
}
|
||||
|
||||
/// Property wrapper marker for snapshot-eligible state. The actual wrapper
|
||||
/// is a no-op at runtime; codegen-tool detection happens via attribute scan.
|
||||
@propertyWrapper
|
||||
public struct Snapshotable<Value> {
|
||||
public var wrappedValue: Value
|
||||
public init(wrappedValue: Value) { self.wrappedValue = wrappedValue }
|
||||
init() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user