Skip to content

Commit 5c83cb6

Browse files
Remove change collection for ChangeTracked (#1450)
* Remove ChangeTracked collect(.byTime(...)) * Send `objectWillChange` on `MainActor` * Update CHANGELOG.md * Add PR link --------- Signed-off-by: Brian Cardarella <[email protected]> Co-authored-by: Brian Cardarella <[email protected]>
1 parent 2dd279f commit 5c83cb6

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
## Changed
1515

1616
## Fixed
17+
- Updates to change-tracked properties no longer occur on the next RunLoop, fixing modal dismissal on macOS (#1450)
1718
- `+` characters are properly encoded as `%2B` in form events (#1449)
1819

1920
## [0.3.0] 2024-08-21

Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
293293
channel.on("phx_close") { [weak self, weak channel] message in
294294
Task { @MainActor in
295295
guard channel === self?.channel else { return }
296-
print("State changed to: phx_close")
297296
self?.internalState = .disconnected
298297
}
299298
}

Sources/LiveViewNative/Property Wrappers/ChangeTracked.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ extension ChangeTracked where Value: AttributeDecodable {
102102
self.previousValue = value
103103
}
104104
cancellable = localValueChanged
105-
.collect(.byTime(RunLoop.current, RunLoop.current.minimumTolerance))
106-
.compactMap(\.last)
107105
.sink(receiveValue: { [weak self] localValue in
108-
self?.objectWillChange.send()
106+
Task { @MainActor [weak self] in
107+
self?.objectWillChange.send()
108+
}
109109
self?.value = localValue
110110
Task { [weak self] in
111111
guard let self,
@@ -118,12 +118,13 @@ extension ChangeTracked where Value: AttributeDecodable {
118118
// set current value to previousValue and trigger update to sync with attribute value
119119
// (may be delayed from localValueChanged due to debounce/throttle)
120120
didSendCancellable = changeTracked.event.owner.handler.didSendSubject
121-
.collect(.byTime(RunLoop.current, RunLoop.current.minimumTolerance))
122121
.sink { [weak self] _ in
123122
guard let self
124123
else { return }
125124
self.previousValue = self.value
126-
self.objectWillChange.send()
125+
Task { @MainActor [weak self] in
126+
self?.objectWillChange.send()
127+
}
127128
}
128129
}
129130
}
@@ -170,10 +171,10 @@ extension ChangeTracked where Value: FormValue {
170171
}
171172

172173
cancellable = localValueChanged
173-
.collect(.byTime(RunLoop.current, RunLoop.current.minimumTolerance))
174-
.compactMap(\.last)
175174
.sink(receiveValue: { [weak self] localValue in
176-
self?.objectWillChange.send()
175+
Task { @MainActor [weak self] in
176+
self?.objectWillChange.send()
177+
}
177178
self?.value = localValue
178179
if changeTracked._event.debounceAttribute != .blur { // the input element should call `pushChangeEvent` when it loses focus.
179180
Task { [weak self] in
@@ -188,12 +189,13 @@ extension ChangeTracked where Value: FormValue {
188189
// set current value to previousValue and trigger update to sync with attribute value
189190
// (may be delayed from localValueChanged due to debounce/throttle)
190191
didSendCancellable = changeTracked.event.owner.handler.didSendSubject
191-
.collect(.byTime(RunLoop.current, RunLoop.current.minimumTolerance))
192-
.sink { [weak self] _ in
192+
.sink { @MainActor [weak self] _ in
193193
guard let self
194194
else { return }
195195
self.previousValue = self.value
196-
self.objectWillChange.send()
196+
Task { @MainActor [weak self] in
197+
self?.objectWillChange.send()
198+
}
197199
}
198200
}
199201

0 commit comments

Comments
 (0)