Skip to content

Commit 4efc094

Browse files
authored
Add support for initializing effect in MergedEffect (#182)
1 parent 01d395d commit 4efc094

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Sources/Atoms/Effect/MergedEffect.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// MergedEffect<each Effect: AtomEffect>
33
/// An atom effect that merges multiple atom effects into one.
44
public struct MergedEffect: AtomEffect {
5+
private let initializing: @MainActor (Context) -> Void
56
private let initialized: @MainActor (Context) -> Void
67
private let updated: @MainActor (Context) -> Void
78
private let released: @MainActor (Context) -> Void
89

910
/// Creates an atom effect that merges multiple atom effects into one.
1011
public init<each Effect: AtomEffect>(_ effect: repeat each Effect) {
12+
initializing = { @Sendable context in
13+
repeat (each effect).initializing(context: context)
14+
}
1115
initialized = { @Sendable context in
1216
repeat (each effect).initialized(context: context)
1317
}
@@ -19,8 +23,14 @@ public struct MergedEffect: AtomEffect {
1923
}
2024
}
2125

22-
/// A lifecycle event that is triggered when the atom is first used and initialized,
23-
/// or once it is released and re-initialized again.
26+
/// A lifecycle event that is triggered before the atom is first used and initialized,
27+
/// or once it is released and re-initialized.
28+
public func initializing(context: Context) {
29+
initializing(context)
30+
}
31+
32+
/// A lifecycle event that is triggered after the atom is first used and initialized,
33+
/// or once it is released and re-initialized.
2434
public func initialized(context: Context) {
2535
initialized(context)
2636
}

0 commit comments

Comments
 (0)