RxProperty
A get-only `BehaviorRelay ` that is (almost) equivalent to ReactiveSwift's `Property`
Install / Use
/learn @inamiy/RxPropertyREADME
RxProperty
A get-only BehaviorRelay that is (almost) equivalent to ReactiveSwift's Property.
This class is highly useful to encapsulate BehaviorRelay inside ViewModel so that other classes cannot reach its setter (unbindable) and make state management safer.
In short:
public final class 💩ViewModel<T> {
// 💩 This is almost the same as `var state: T`.
// DON'T EXPOSE VARIABLE!
public let state = BehaviorRelay<T>(...)
// 💩 Exposing `Observable` is NOT a good solution either
// because type doesn't tell us that it contains at least one value
// and we cannot even "extract" it.
public var stateObservable: Observable<T> {
return state.asObservable()
}
}
public final class 👍ViewModel<T> {
// 👍 Hide variable.
private let _state = BehaviorRelay<T>(...)
// 👍 `Property` is a better type than `Observable`.
public let state: Property<T>
public init() {
self.state = Property(_state)
}
}
Disclaimer
Since this library should rather go to RxSwift-core, there is no plan to release as a 3rd-party microframework for CocoaPods/Carthage ~~/SwiftPackageManager~~.
(Swift Package Manager is supported in inamiy/RxProperty#5)
If you like it, please upvote ReactiveX/RxSwift#1118 and join the discussion. Current recommended way is to directly use the source code to your project.
License
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
