Skip to content

Commit 69f7393

Browse files
Add didChange publisher (#8)
Publishes actions immediately after state changes. This should offer enough API surface to: - Wire Arboreal Stores into SwiftUI Combine-driven things such as `onReceive()` and `ObservableObject` - Perform most updates in imperative UIKit code, since you have both the action that caused the update, and the update itself
1 parent ef279db commit 69f7393

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Sources/Arboreal/Arboreal.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99
import Observation
1010
import os
11+
import Combine
1112

1213
/// State is described with models.
1314
/// A model is any type that knows how to update itself in response to actions.
@@ -191,6 +192,13 @@ public final class Store<Model: ModelProtocol>: StoreProtocol {
191192
/// to generate side effects such as DB queries or API calls.
192193
@ObservationIgnored public var environment: Model.Environment
193194

195+
@ObservationIgnored public var _didChange =
196+
PassthroughSubject<Model.Action, Never>()
197+
198+
var didChange: AnyPublisher<Model.Action, Never> {
199+
_didChange.eraseToAnyPublisher()
200+
}
201+
194202
/// A read-only view of the current state.
195203
/// Nested models and other reference types should also mark their
196204
/// properties read-only. All state updates should go through
@@ -252,6 +260,7 @@ public final class Store<Model: ModelProtocol>: StoreProtocol {
252260
action: action,
253261
environment: environment
254262
)
263+
_didChange.send(action)
255264
runner.run(fx)
256265
}
257266
}

0 commit comments

Comments
 (0)