mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Switch to weakAssign for all AppSettings listeners
This commit is contained in:
committed by
Stefan Ceriu
parent
98cfc2c9fb
commit
a02b461c37
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
extension Publisher where Self.Failure == Never {
|
||||
func weakAssign<Root: AnyObject>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable {
|
||||
sink { [weak object] value in
|
||||
object?[keyPath: keyPath] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,10 +79,9 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
return self.contextMenuActionsForItemId(itemId)
|
||||
}
|
||||
|
||||
ServiceLocator.shared.settings.$timelineStyle.sink { [weak self] timelineStyle in
|
||||
self?.state.timelineStyle = timelineStyle
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
ServiceLocator.shared.settings.$timelineStyle
|
||||
.weakAssign(to: \.state.timelineStyle, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
buildTimelineViews()
|
||||
}
|
||||
|
||||
@@ -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