Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ A context that can simulate any scenarios in which atoms are used from a view or
|:--|:--|
|[unwatch(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/unwatch(_:))|Simulates a scenario in which the atom is no longer watched.|
|[override(_:with:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/override(_:with:)-1ce4h)|Overwrites the output of a specific atom or all atoms of the given type with the fixed value.|
|[observe(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/observe(_:))|Observes updates with a snapshot that captures a specific set of values of atoms.|
|[waitUntilNextUpdate(timeout:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/waituntilnextupdate(timeout:))|Waits until any of atoms watched through this context is updated.|
|[onUpdate](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/onupdate)|Sets a closure that notifies there has been an update to one of the atoms.|

Expand Down
16 changes: 1 addition & 15 deletions Sources/Atoms/Context/AtomTestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ public struct AtomTestContext: AtomWatchableContext {
public func override<Node: Atom>(_ atomType: Node.Type, with value: @escaping (Node) -> Node.Loader.Value) {
state.overrides.insert(atomType, with: value)
}

/// Observes updates with a snapshot that captures specific set of values of atoms.
///
/// Use this to monitor and debugging the atoms or for producing side effects.
///
/// - Parameter onUpdate: A closure to handle a snapshot of recent updates.
public func observe(_ onUpdate: @escaping @MainActor (Snapshot) -> Void) {
state.observers.append(Observer(onUpdate: onUpdate))
}
}

private extension AtomTestContext {
Expand All @@ -274,16 +265,11 @@ private extension AtomTestContext {
private let _container = SubscriptionContainer()

var overrides = Overrides()
var observers = [Observer]()
let notifier = PassthroughSubject<Void, Never>()
var onUpdate: (() -> Void)?

var store: StoreContext {
StoreContext(
_store,
overrides: overrides,
observers: observers
)
StoreContext(_store, overrides: overrides)
}

var container: SubscriptionContainer.Wrapper {
Expand Down
24 changes: 0 additions & 24 deletions Tests/AtomsTests/Context/AtomTestContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,6 @@ final class AtomTestContextTests: XCTestCase {
XCTAssertEqual(context.read(atom1), 300)
}

func testObserve() {
let atom = TestStateAtom(defaultValue: 100)
var snapshots0 = [Snapshot]()
var snapshots1 = [Snapshot]()
let context = AtomTestContext()

context.observe { snapshots0.append($0) }
context.observe { snapshots1.append($0) }
context.watch(atom)

XCTAssertEqual(snapshots0.count, 1)
XCTAssertEqual(snapshots1.count, 1)

context[atom] = 200

XCTAssertEqual(snapshots0.count, 2)
XCTAssertEqual(snapshots1.count, 2)

context.unwatch(atom)

XCTAssertEqual(snapshots0.count, 3)
XCTAssertEqual(snapshots1.count, 3)
}

func testTerminate() {
let atom = TestStateAtom(defaultValue: 100)
let context = AtomTestContext()
Expand Down