Skip to content
Merged
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
14 changes: 12 additions & 2 deletions Sources/Atoms/Effect/MergedEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// MergedEffect<each Effect: AtomEffect>
/// An atom effect that merges multiple atom effects into one.
public struct MergedEffect: AtomEffect {
private let initializing: @MainActor (Context) -> Void
private let initialized: @MainActor (Context) -> Void
private let updated: @MainActor (Context) -> Void
private let released: @MainActor (Context) -> Void

/// Creates an atom effect that merges multiple atom effects into one.
public init<each Effect: AtomEffect>(_ effect: repeat each Effect) {
initializing = { @Sendable context in
repeat (each effect).initializing(context: context)
}
initialized = { @Sendable context in
repeat (each effect).initialized(context: context)
}
Expand All @@ -19,8 +23,14 @@ public struct MergedEffect: AtomEffect {
}
}

/// A lifecycle event that is triggered when the atom is first used and initialized,
/// or once it is released and re-initialized again.
/// A lifecycle event that is triggered before the atom is first used and initialized,
/// or once it is released and re-initialized.
public func initializing(context: Context) {
initializing(context)
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to initializing(context) inside public func initializing refers to the method itself, causing infinite recursion. Rename the private closure property (e.g., to _initializing or initializingHandler) or adjust the call to disambiguate the closure (for example self._initializing(context)).

Suggested change
initializing(context)
_initializing(context)

Copilot uses AI. Check for mistakes.
}

/// A lifecycle event that is triggered after the atom is first used and initialized,
/// or once it is released and re-initialized.
public func initialized(context: Context) {
initialized(context)
}
Expand Down