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
12 changes: 0 additions & 12 deletions Sources/Atoms/Atom/Atom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public protocol Atom {
/// with other atoms.
typealias UpdatedContext = AtomUpdatedContext

/// A boolean value indicating whether the atom value should be preserved even if
/// no longer watched to.
///
/// It's recommended to conform the ``KeepAlive`` to this atom, instead of overriding
/// this property to return `true`.
/// The default is `false`.
static var shouldKeepAlive: Bool { get }

/// A unique value used to identify the atom internally.
///
/// This key don't have to be unique with respect to other atoms in the entire application
Expand Down Expand Up @@ -70,10 +62,6 @@ public protocol Atom {
}

public extension Atom {
static var shouldKeepAlive: Bool {
false
}

func makeCoordinator() -> Coordinator where Coordinator == Void {
()
}
Expand Down
5 changes: 0 additions & 5 deletions Sources/Atoms/Core/AtomCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ internal protocol AtomCacheProtocol: CustomStringConvertible {

var atom: Node { get set }
var value: Node.Loader.Value? { get set }
var shouldKeepAlive: Bool { get }

func reset(with store: StoreContext)
}
Expand All @@ -19,10 +18,6 @@ internal struct AtomCache<Node: Atom>: AtomCacheProtocol {
var atom: Node
var value: Node.Loader.Value?

var shouldKeepAlive: Bool {
Node.shouldKeepAlive
}

func reset(with store: StoreContext) {
store.reset(atom)
}
Expand Down
9 changes: 4 additions & 5 deletions Sources/Atoms/Core/StoreContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,10 @@ private extension StoreContext {
// 1. It's not marked as `KeepAlive`.
// 2. It has no downstream atoms.
// 3. It has no subscriptions from views.
let shouldKeepAlive = store.state.caches[key]?.shouldKeepAlive ?? false
let shouldRelease =
!shouldKeepAlive
&& (store.graph.children[key]?.isEmpty ?? true)
&& (store.state.subscriptions[key]?.isEmpty ?? true)
let shouldKeepAlive = store.state.caches[key].map { $0 is any KeepAlive } ?? false
let isChildrenEmpty = store.graph.children[key]?.isEmpty ?? true
let isSubscriptionEmpty = store.state.subscriptions[key]?.isEmpty ?? true
let shouldRelease = !shouldKeepAlive && isChildrenEmpty && isSubscriptionEmpty

guard shouldRelease else {
return
Expand Down
6 changes: 0 additions & 6 deletions Sources/Atoms/KeepAlive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@
/// ```
///
public protocol KeepAlive where Self: Atom {}

public extension KeepAlive {
static var shouldKeepAlive: Bool {
true
}
}
14 changes: 0 additions & 14 deletions Tests/AtomsTests/Core/AtomCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ import XCTest

@MainActor
final class AtomCacheTests: XCTestCase {
func testShouldKeepAlive() {
struct KeepAliveAtom: ValueAtom, KeepAlive, Hashable {
func value(context: Context) -> Int {
0
}
}

let cache0 = AtomCache(atom: TestValueAtom(value: 0))
let cache1 = AtomCache(atom: KeepAliveAtom())

XCTAssertFalse(cache0.shouldKeepAlive)
XCTAssertTrue(cache1.shouldKeepAlive)
}

func testReset() {
let store = AtomStore()
let context = StoreContext(store)
Expand Down
23 changes: 0 additions & 23 deletions Tests/AtomsTests/KeepAliveTests.swift

This file was deleted.