-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Do not propagate dependencies to effect actions. #1954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ public final class Store<State, Action> { | |
private let reducer: (inout State, Action) -> EffectTask<Action> | ||
fileprivate var scope: AnyStoreScope? | ||
#endif | ||
var state: CurrentValueSubject<State, Never> | ||
@_spi(Internals) public var state: CurrentValueSubject<State, Never> | ||
#if DEBUG | ||
private let mainThreadChecksEnabled: Bool | ||
#endif | ||
|
@@ -385,28 +385,31 @@ public final class Store<State, Action> { | |
var didComplete = false | ||
let boxedTask = Box<Task<Void, Never>?>(wrappedValue: nil) | ||
let uuid = UUID() | ||
let effectCancellable = | ||
let effectCancellable = withEscapedDependencies { continuation in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. easier to review this diff with whitespace turned off. |
||
publisher | ||
.handleEvents( | ||
receiveCancel: { [weak self] in | ||
self?.threadCheck(status: .effectCompletion(action)) | ||
self?.effectCancellables[uuid] = nil | ||
} | ||
) | ||
.sink( | ||
receiveCompletion: { [weak self] _ in | ||
self?.threadCheck(status: .effectCompletion(action)) | ||
boxedTask.wrappedValue?.cancel() | ||
didComplete = true | ||
self?.effectCancellables[uuid] = nil | ||
}, | ||
receiveValue: { [weak self] effectAction in | ||
guard let self = self else { return } | ||
if let task = self.send(effectAction, originatingFrom: action) { | ||
tasks.wrappedValue.append(task) | ||
.handleEvents( | ||
receiveCancel: { [weak self] in | ||
self?.threadCheck(status: .effectCompletion(action)) | ||
self?.effectCancellables[uuid] = nil | ||
} | ||
} | ||
) | ||
) | ||
.sink( | ||
receiveCompletion: { [weak self] _ in | ||
self?.threadCheck(status: .effectCompletion(action)) | ||
boxedTask.wrappedValue?.cancel() | ||
didComplete = true | ||
self?.effectCancellables[uuid] = nil | ||
}, | ||
receiveValue: { [weak self] effectAction in | ||
guard let self = self else { return } | ||
if let task = continuation.yield({ | ||
self.send(effectAction, originatingFrom: action) | ||
}) { | ||
tasks.wrappedValue.append(task) | ||
} | ||
} | ||
) | ||
} | ||
|
||
if !didComplete { | ||
let task = Task<Void, Never> { @MainActor in | ||
|
@@ -418,43 +421,47 @@ public final class Store<State, Action> { | |
self.effectCancellables[uuid] = effectCancellable | ||
} | ||
case let .run(priority, operation): | ||
tasks.wrappedValue.append( | ||
Task(priority: priority) { @MainActor in | ||
#if DEBUG | ||
var isCompleted = false | ||
defer { isCompleted = true } | ||
#endif | ||
await operation( | ||
EffectTask<Action>.Send { | ||
#if DEBUG | ||
if isCompleted { | ||
runtimeWarn( | ||
""" | ||
An action was sent from a completed effect: | ||
|
||
Action: | ||
\(debugCaseOutput($0)) | ||
|
||
Effect returned from: | ||
\(debugCaseOutput(action)) | ||
|
||
Avoid sending actions using the 'send' argument from 'EffectTask.run' after \ | ||
the effect has completed. This can happen if you escape the 'send' argument in \ | ||
an unstructured context. | ||
|
||
To fix this, make sure that your 'run' closure does not return until you're \ | ||
done calling 'send'. | ||
""" | ||
) | ||
withEscapedDependencies { continuation in | ||
tasks.wrappedValue.append( | ||
Task(priority: priority) { @MainActor in | ||
#if DEBUG | ||
var isCompleted = false | ||
defer { isCompleted = true } | ||
#endif | ||
await operation( | ||
EffectTask<Action>.Send { effectAction in | ||
#if DEBUG | ||
if isCompleted { | ||
runtimeWarn( | ||
""" | ||
An action was sent from a completed effect: | ||
|
||
Action: | ||
\(debugCaseOutput(effectAction)) | ||
|
||
Effect returned from: | ||
\(debugCaseOutput(action)) | ||
|
||
Avoid sending actions using the 'send' argument from 'EffectTask.run' after \ | ||
the effect has completed. This can happen if you escape the 'send' argument in \ | ||
an unstructured context. | ||
|
||
To fix this, make sure that your 'run' closure does not return until you're \ | ||
done calling 'send'. | ||
""" | ||
) | ||
} | ||
#endif | ||
if let task = continuation.yield({ | ||
self.send(effectAction, originatingFrom: action) | ||
}) { | ||
tasks.wrappedValue.append(task) | ||
} | ||
#endif | ||
if let task = self.send($0, originatingFrom: action) { | ||
tasks.wrappedValue.append(task) | ||
} | ||
} | ||
) | ||
} | ||
) | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this so that I could more fully test the
Store
in complete isolation (no need to interface withViewStore
). I just wanted to be 100% we were asserting on the full behavior inside the store without outside factors.