-
-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Checklist
- Reviewed the README and documentation.
- Checked existing issues & PRs to ensure not duplicated.
Description
The current observability API done with AtomObserver has too few functionalities as it just can observe what atom is registered/released/updated and that's it.
It would be better to support more powerful functionalities like accessing arbitrary atom values through a Snapshot structure.
Also, currently Snapshot.restore() can only reset the current value to be the snapshotted value, but it should reset the whole store state to be the snapshotted one to prevent inconsistency.
Example Use Case
@State
var snapshots: [Snapshot]
@State
var position = 0
var body: some View {
AtomRelay {
ZStack {
// ... content
timeTravelSlider
}
}
.observe { snapshot in
Task {
snapshots.append(snapshot)
}
}
}
var timeTravelSlider: some View {
Slider(
value: Binding(
get: { Double(position) },
set: {
position = Int($0)
snapshots[position].restore()
}
),
in: 0...Double(max(0, snapshots.endIndex - 1))
)
}Alternative Solution
N/A
Proposed Solution
- Obsolete the current
AtomObserverand related classes. - Handle atom events with an internal
Observerclass. - Capture the whole store state and restore it through
Snapshot. - Add
lookup<Node: Atom>(_ atom: Node) -> Node.Loader.Value?method to get value through a snapshot.
Motivation & Context
As described.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request