File tree Expand file tree Collapse file tree 6 files changed +4
-65
lines changed Expand file tree Collapse file tree 6 files changed +4
-65
lines changed Original file line number Diff line number Diff line change @@ -23,14 +23,6 @@ public protocol Atom {
2323 /// with other atoms.
2424 typealias UpdatedContext = AtomUpdatedContext
2525
26- /// A boolean value indicating whether the atom value should be preserved even if
27- /// no longer watched to.
28- ///
29- /// It's recommended to conform the ``KeepAlive`` to this atom, instead of overriding
30- /// this property to return `true`.
31- /// The default is `false`.
32- static var shouldKeepAlive : Bool { get }
33-
3426 /// A unique value used to identify the atom internally.
3527 ///
3628 /// This key don't have to be unique with respect to other atoms in the entire application
@@ -70,10 +62,6 @@ public protocol Atom {
7062}
7163
7264public extension Atom {
73- static var shouldKeepAlive : Bool {
74- false
75- }
76-
7765 func makeCoordinator( ) -> Coordinator where Coordinator == Void {
7866 ( )
7967 }
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ internal protocol AtomCacheProtocol: CustomStringConvertible {
44
55 var atom : Node { get set }
66 var value : Node . Loader . Value ? { get set }
7- var shouldKeepAlive : Bool { get }
87
98 func reset( with store: StoreContext )
109}
@@ -19,10 +18,6 @@ internal struct AtomCache<Node: Atom>: AtomCacheProtocol {
1918 var atom : Node
2019 var value : Node . Loader . Value ?
2120
22- var shouldKeepAlive : Bool {
23- Node . shouldKeepAlive
24- }
25-
2621 func reset( with store: StoreContext ) {
2722 store. reset ( atom)
2823 }
Original file line number Diff line number Diff line change @@ -423,11 +423,10 @@ private extension StoreContext {
423423 // 1. It's not marked as `KeepAlive`.
424424 // 2. It has no downstream atoms.
425425 // 3. It has no subscriptions from views.
426- let shouldKeepAlive = store. state. caches [ key] ? . shouldKeepAlive ?? false
427- let shouldRelease =
428- !shouldKeepAlive
429- && ( store. graph. children [ key] ? . isEmpty ?? true )
430- && ( store. state. subscriptions [ key] ? . isEmpty ?? true )
426+ let shouldKeepAlive = store. state. caches [ key] . map { $0 is any KeepAlive } ?? false
427+ let isChildrenEmpty = store. graph. children [ key] ? . isEmpty ?? true
428+ let isSubscriptionEmpty = store. state. subscriptions [ key] ? . isEmpty ?? true
429+ let shouldRelease = !shouldKeepAlive && isChildrenEmpty && isSubscriptionEmpty
431430
432431 guard shouldRelease else {
433432 return
Original file line number Diff line number Diff line change 1212/// ```
1313///
1414public protocol KeepAlive where Self: Atom { }
15-
16- public extension KeepAlive {
17- static var shouldKeepAlive : Bool {
18- true
19- }
20- }
Original file line number Diff line number Diff line change @@ -4,20 +4,6 @@ import XCTest
44
55@MainActor
66final class AtomCacheTests : XCTestCase {
7- func testShouldKeepAlive( ) {
8- struct KeepAliveAtom : ValueAtom , KeepAlive , Hashable {
9- func value( context: Context ) -> Int {
10- 0
11- }
12- }
13-
14- let cache0 = AtomCache ( atom: TestValueAtom ( value: 0 ) )
15- let cache1 = AtomCache ( atom: KeepAliveAtom ( ) )
16-
17- XCTAssertFalse ( cache0. shouldKeepAlive)
18- XCTAssertTrue ( cache1. shouldKeepAlive)
19- }
20-
217 func testReset( ) {
228 let store = AtomStore ( )
239 let context = StoreContext ( store)
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments