@@ -99,14 +99,8 @@ import SwiftUI
9999#else
100100 @preconcurrency @MainActor
101101#endif
102- public final class Store < State, Action> : _Store {
102+ public final class Store < State, Action> {
103103 var children : [ ScopeID < State , Action > : AnyObject ] = [ : ]
104- private weak var parent : ( any _Store ) ?
105- private let scopeID : AnyHashable ?
106-
107- func removeChild( scopeID: AnyHashable ) {
108- children [ scopeID as! ScopeID < State , Action > ] = nil
109- }
110104
111105 let core : any Core < State , Action >
112106 @_spi ( Internals) public var effectCancellables : [ UUID : AnyCancellable ] { core. effectCancellables }
@@ -146,7 +140,6 @@ public final class Store<State, Action>: _Store {
146140
147141 init ( ) {
148142 self . core = InvalidCore ( )
149- self . scopeID = nil
150143 }
151144
152145 deinit {
@@ -280,7 +273,7 @@ public final class Store<State, Action>: _Store {
280273 let id,
281274 let child = children [ id] as? Store < ChildState , ChildAction >
282275 else {
283- let child = Store < ChildState , ChildAction > ( core: childCore ( ) , scopeID : id , parent : self )
276+ let child = Store < ChildState , ChildAction > ( core: childCore ( ) )
284277 if core. canStoreCacheChildren, let id {
285278 children [ id] = child
286279 }
@@ -327,24 +320,18 @@ public final class Store<State, Action>: _Store {
327320 core. send ( action)
328321 }
329322
330- private init ( core: some Core < State , Action > , scopeID : AnyHashable ? , parent : ( any _Store ) ? ) {
323+ private init ( core: some Core < State , Action > ) {
331324 defer { Logger . shared. log ( " \( storeTypeName ( of: self ) ) .init " ) }
332325 self . core = core
333- self . parent = parent
334- self . scopeID = scopeID
335326
336327 if let stateType = State . self as? any ObservableState . Type {
337328 func subscribeToDidSet< T: ObservableState > ( _ type: T . Type ) -> AnyCancellable {
338329 return core. didSet
339- . prefix { [ weak self] _ in self ? . core. isInvalid == false }
340- . compactMap { [ weak self] in ( self ? . withState ( \ . self ) as? T ) ? . _$id }
330+ . prefix { [ weak self] _ in self ? . core. isInvalid != true }
331+ . compactMap { [ weak self] in ( self ? . currentState as? T ) ? . _$id }
341332 . removeDuplicates ( )
342333 . dropFirst ( )
343- . sink { [ weak self, weak parent] _ in
344- guard let scopeID = self ? . scopeID
345- else { return }
346- parent? . removeChild ( scopeID: scopeID)
347- } receiveValue: { [ weak self] _ in
334+ . sink { [ weak self] _ in
348335 guard let self else { return }
349336 self . _$observationRegistrar. withMutation ( of: self , keyPath: \. currentState) { }
350337 }
@@ -357,11 +344,7 @@ public final class Store<State, Action>: _Store {
357344 initialState: R . State ,
358345 reducer: R
359346 ) {
360- self . init (
361- core: RootCore ( initialState: initialState, reducer: reducer) ,
362- scopeID: nil ,
363- parent: nil
364- )
347+ self . init ( core: RootCore ( initialState: initialState, reducer: reducer) )
365348 }
366349
367350 /// A publisher that emits when state changes.
@@ -589,8 +572,3 @@ let _isStorePerceptionCheckingEnabled: Bool = {
589572 @available ( iOS 17 , macOS 14 , tvOS 17 , watchOS 10 , * )
590573 extension Store : Observable { }
591574#endif
592-
593- @MainActor
594- private protocol _Store : AnyObject {
595- func removeChild( scopeID: AnyHashable )
596- }
0 commit comments