mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Switch to weakAssign for all AppSettings listeners
This commit is contained in:
committed by
Stefan Ceriu
parent
98cfc2c9fb
commit
a02b461c37
@@ -33,7 +33,9 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
showSessionVerificationSection: !(userSession.sessionVerificationController?.isVerified ?? false)),
|
||||
imageProvider: userSession.mediaProvider)
|
||||
|
||||
listenToSettingsChange(publisher: ServiceLocator.shared.settings.$timelineStyle, keyPath: \.timelineStyle)
|
||||
ServiceLocator.shared.settings.$timelineStyle
|
||||
.weakAssign(to: \.state.bindings.timelineStyle, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
Task {
|
||||
if case let .success(userAvatarURL) = await userSession.clientProxy.loadUserAvatarURL() {
|
||||
@@ -78,16 +80,4 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
ServiceLocator.shared.settings.timelineStyle = state.bindings.timelineStyle
|
||||
}
|
||||
}
|
||||
|
||||
private func listenToSettingsChange<Value>(publisher: AnyPublisher<Value, Never>,
|
||||
keyPath: WritableKeyPath<SettingsScreenViewStateBindings, Value>) where Value: Equatable {
|
||||
publisher.sink { [weak self] newValue in
|
||||
guard newValue != self?.state.bindings[keyPath: keyPath] else {
|
||||
return
|
||||
}
|
||||
|
||||
self?.state.bindings[keyPath: keyPath] = newValue
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user