@@ -117,7 +117,30 @@ public struct AtomRelationContext: AtomWatchableContext {
117117 @inlinable
118118 @discardableResult
119119 public func watch< Node: Atom > ( _ atom: Node ) -> Node . Hook . Value {
120- _box. watch ( atom)
120+ _box. watch ( atom, shouldNotifyAfterUpdates: false )
121+ }
122+
123+ /// Accesses the observable object associated with the given atom for reading and initialing watch to
124+ /// receive its updates.
125+ ///
126+ /// This method returns an observable object for the given atom and initiate watching the atom so that
127+ /// the current context to get updated when the atom notifies updates.
128+ /// The observable object associated with the atom is cached until it is no longer watched to or until
129+ /// it is updated.
130+ ///
131+ /// ```swift
132+ /// let context = ...
133+ /// let store = context.watch(AccountStoreAtom())
134+ /// print(store.currentUser) // Prints the user value after update.
135+ /// ```
136+ ///
137+ /// - Parameter atom: An atom that associates the observable object.
138+ ///
139+ /// - Returns: The observable object associated with the given atom.
140+ @inlinable
141+ @discardableResult
142+ public func watch< Node: Atom > ( _ atom: Node ) -> Node . Hook . Value where Node. Hook: AtomObservableObjectHook {
143+ _box. watch ( atom, shouldNotifyAfterUpdates: true )
121144 }
122145
123146 /// Add the termination action that will be performed when the atom will no longer be watched to
@@ -175,7 +198,7 @@ public struct AtomRelationContext: AtomWatchableContext {
175198internal protocol _AnyAtomRelationContextBox {
176199 var store : AtomStore { get }
177200
178- func watch< Node: Atom > ( _ atom: Node ) -> Node . Hook . Value
201+ func watch< Node: Atom > ( _ atom: Node , shouldNotifyAfterUpdates : Bool ) -> Node . Hook . Value
179202 func addTermination( _ termination: @MainActor @escaping ( ) -> Void )
180203 func keepUntilTermination< Object: AnyObject > ( _ object: Object )
181204}
@@ -200,8 +223,12 @@ internal struct _AtomRelationContextBox<Caller: Atom>: _AnyAtomRelationContextBo
200223 let store : AtomStore
201224
202225 @usableFromInline
203- func watch< Node: Atom > ( _ atom: Node ) -> Node . Hook . Value {
204- store. watch ( atom, belongTo: caller)
226+ func watch< Node: Atom > ( _ atom: Node , shouldNotifyAfterUpdates: Bool ) -> Node . Hook . Value {
227+ store. watch (
228+ atom,
229+ belongTo: caller,
230+ shouldNotifyAfterUpdates: shouldNotifyAfterUpdates
231+ )
205232 }
206233
207234 @usableFromInline
0 commit comments