Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8a03e6a
wip
stephencelis Sep 13, 2024
3fe6fb0
wip
stephencelis Sep 13, 2024
9122a3a
wip
stephencelis Sep 13, 2024
f80cb3b
wip
stephencelis Sep 13, 2024
f67562a
wip
stephencelis Sep 13, 2024
2bd4f44
wip
stephencelis Sep 13, 2024
00ad75e
wip
stephencelis Sep 13, 2024
65c42e1
wip
stephencelis Sep 13, 2024
e79668e
wip
stephencelis Sep 13, 2024
0665585
wip
stephencelis Sep 13, 2024
a5e7734
wip
stephencelis Sep 13, 2024
0d630e2
wip
stephencelis Sep 13, 2024
edbf4e6
wip
stephencelis Sep 13, 2024
0ae2e54
Merge remote-tracking branch 'origin/main' into core
stephencelis Sep 13, 2024
26e41f9
wip
stephencelis Sep 13, 2024
f4da4c6
wip
stephencelis Sep 13, 2024
33cc53e
wip
stephencelis Sep 13, 2024
052841e
wip
stephencelis Sep 13, 2024
e34e628
wip
stephencelis Sep 13, 2024
712fa8d
wip
stephencelis Sep 14, 2024
d9eb1f6
wip
stephencelis Sep 14, 2024
603d725
Merge remote-tracking branch 'origin/main' into core
stephencelis Sep 19, 2024
62a61c3
get rid of originating action
mbrandonw Sep 27, 2024
c70426f
wip
stephencelis Oct 2, 2024
bef3861
Merge remote-tracking branch 'origin/main' into core
stephencelis Oct 8, 2024
e58cba5
Merge remote-tracking branch 'origin/main' into core
stephencelis Oct 16, 2024
c3338b5
Merge remote-tracking branch 'origin/main' into core
stephencelis Oct 21, 2024
413c24c
Merge branch 'main' into core
stephencelis Nov 12, 2024
bbe33b7
Merge remote-tracking branch 'origin/main' into core
stephencelis Feb 6, 2025
47d606b
Merge remote-tracking branch 'origin/main' into core
stephencelis Feb 27, 2025
58fddea
Merge remote-tracking branch 'origin/main' into core
stephencelis Feb 27, 2025
1b7f72c
wip
stephencelis Feb 28, 2025
5714403
Merge remote-tracking branch 'origin/main' into core
stephencelis Mar 13, 2025
95570eb
Deprecate non-writable scopes
stephencelis Mar 13, 2025
31b0755
Revert "Deprecate non-writable scopes"
stephencelis Mar 13, 2025
f05ac83
Merge branch 'main' into core
stephencelis Mar 26, 2025
725189d
wip
stephencelis Mar 26, 2025
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
stephencelis committed Sep 13, 2024
commit f80cb3b51c3a35d4bd1d90724f543fddec03e32a
18 changes: 16 additions & 2 deletions Sources/ComposableArchitecture/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ protocol Core<State, Action>: AnyObject, Sendable {
func send(_ action: Action) -> Task<Void, Never>?

var didSet: CurrentValueRelay<Void> { get }
var isInvalid: Bool { get }
}

final class InvalidCore<State, Action>: Core {
Expand All @@ -19,6 +20,7 @@ final class InvalidCore<State, Action>: Core {
func send(_ action: Action) -> Task<Void, Never>? { nil }

let didSet = CurrentValueRelay<Void>(())
let isInvalid = true
}

final class RootCore<Root: Reducer>: Core {
Expand All @@ -28,9 +30,12 @@ final class RootCore<Root: Reducer>: Core {
}
}
let reducer: Root
var bufferedActions: [Root.Action] = []

let didSet = CurrentValueRelay(())
var effectCancellables: [UUID: AnyCancellable] = [:]
let isInvalid = false

private var bufferedActions: [Root.Action] = []
private var effectCancellables: [UUID: AnyCancellable] = [:]
private var isSending = false
init(
initialState: Root.State,
Expand Down Expand Up @@ -192,6 +197,9 @@ class ScopedCore<Base: Core, State, Action>: Core {
var didSet: CurrentValueRelay<Void> {
base.didSet
}
var isInvalid: Bool {
base.isInvalid
}
}

class IfLetCore<Base: Core, State, Action>: Core {
Expand Down Expand Up @@ -224,6 +232,9 @@ class IfLetCore<Base: Core, State, Action>: Core {
var didSet: CurrentValueRelay<Void> {
base.didSet
}
var isInvalid: Bool {
base.state[keyPath: stateKeyPath] == nil || base.isInvalid
}
}

class ClosureScopedCore<Base: Core, State, Action>: Core {
Expand All @@ -248,4 +259,7 @@ class ClosureScopedCore<Base: Core, State, Action>: Core {
var didSet: CurrentValueRelay<Void> {
base.didSet
}
var isInvalid: Bool {
base.isInvalid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ extension Store where State: ObservableState, Action: BindableAction, Action.Sta
get { self.state[keyPath: keyPath] }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.set(keyPath, newValue, isInvalidated: _isInvalidated))
self.send(
.set(keyPath, newValue, isInvalidated: { [weak self] in self?.core.isInvalid ?? true })
)
}
}
}
Expand All @@ -181,7 +183,9 @@ where
get { self.observableState }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.set(\.self, newValue, isInvalidated: _isInvalidated))
self.send(
.set(\.self, newValue, isInvalidated: { [weak self] in self?.core.isInvalid ?? true })
)
}
}
}
Expand All @@ -200,7 +204,11 @@ where
get { self.state[keyPath: keyPath] }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.view(.set(keyPath, newValue, isInvalidated: _isInvalidated)))
self.send(
.view(
.set(keyPath, newValue, isInvalidated: { [weak self] in self?.core.isInvalid ?? true })
)
)
}
}
}
Expand All @@ -218,7 +226,11 @@ where
get { self.observableState }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.view(.set(\.self, newValue, isInvalidated: _isInvalidated)))
self.send(
.view(
.set(\.self, newValue, isInvalidated: { [weak self] in self?.core.isInvalid ?? true })
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ extension Store where State: ObservableState {
if newValue == nil,
let childState = self.state[keyPath: state],
id == _identifiableID(childState),
!self._isInvalidated()
!self.core.isInvalid
{
self.send(action(.dismiss))
if self.state[keyPath: state] != nil {
Expand Down
2 changes: 0 additions & 2 deletions Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ import SwiftUI
public final class Store<State, Action> {
var canCacheChildren = true
var children: [ScopeID<State, Action>: AnyObject] = [:]
var _isInvalidated: @MainActor @Sendable () -> Bool = { false }

let core: any Core<State, Action>

Expand Down Expand Up @@ -176,7 +175,6 @@ public final class Store<State, Action> {
}

init() {
self._isInvalidated = { true }
self.core = InvalidCore()
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/ComposableArchitecture/SwiftUI/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewSt
value: value,
bindableActionType: ViewAction.self,
context: .bindingState,
isInvalidated: self.store._isInvalidated,
isInvalidated: { [weak self] in self?.store.core.isInvalid ?? true },
fileID: bindingState.fileID,
filePath: bindingState.filePath,
line: bindingState.line,
Expand Down Expand Up @@ -460,7 +460,7 @@ public struct BindingViewStore<State> {
value: value,
bindableActionType: self.bindableActionType,
context: .bindingStore,
isInvalidated: self.store._isInvalidated,
isInvalidated: { [weak store] in store?.core.isInvalid ?? true },
fileID: self.fileID,
filePath: self.filePath,
line: self.line,
Expand Down