Created
November 21, 2018 01:29
-
-
Save AlexanderBollbach/4a12c832ce5921aa26d0e0b48f62b233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SettingsControllerFacade { | |
private let bag = DisposeBag() | |
private let controller: SettingsControllerType | |
private let _settingGroups = PublishSubject<[SettingGroup]>() | |
init( | |
controller: SettingsControllerType | |
) { | |
self.controller = controller | |
} | |
var settingGroups: Observable<[SettingGroup]> { | |
return _settingGroups | |
.asObservable() | |
} | |
private func notify() { | |
self._settingGroups.onNext(self.controller.settingGroups) | |
} | |
func resetWith(o: Observable<Void>) { | |
o.subscribe(onNext: { [unowned self] _ in | |
self.controller.reset() | |
self.notify() | |
}) | |
.disposed(by: bag) | |
} | |
func updateSettingWith(o: Observable<(SettingKey, SettingValue)>) { | |
o.subscribe(onNext: { [unowned self] kv in | |
self.controller.updateSetting(key: kv.0, value: kv.1) | |
self.notify() | |
}) | |
.disposed(by: bag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment