Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inamiy/rxproperty
A get-only `BehaviorRelay ` that is (almost) equivalent to ReactiveSwift's `Property`
https://github.com/inamiy/rxproperty
Last synced: 17 days ago
JSON representation
A get-only `BehaviorRelay ` that is (almost) equivalent to ReactiveSwift's `Property`
- Host: GitHub
- URL: https://github.com/inamiy/rxproperty
- Owner: inamiy
- License: mit
- Created: 2017-03-11T00:24:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-12T19:10:47.000Z (over 3 years ago)
- Last Synced: 2024-10-15T21:08:02.745Z (28 days ago)
- Language: Swift
- Homepage:
- Size: 16.6 KB
- Stars: 85
- Watchers: 2
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RxProperty
A get-only `BehaviorRelay` that is (almost) equivalent to [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift)'s [`Property`](https://github.com/ReactiveCocoa/ReactiveSwift/blob/1.1.0/Sources/Property.swift#L455).
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:
```swift
public final class đź’©ViewModel {
// đź’© This is almost the same as `var state: T`.
// DON'T EXPOSE VARIABLE!
public let state = BehaviorRelay(...)// đź’© 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 {
return state.asObservable()
}
}
``````swift
public final class đź‘ŤViewModel {
// đź‘Ť Hide variable.
private let _state = BehaviorRelay(...)// đź‘Ť `Property` is a better type than `Observable`.
  public let state: Property
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](https://github.com/inamiy/RxProperty/pull/5))
If you like it, please upvote [ReactiveX/RxSwift#1118](https://github.com/ReactiveX/RxSwift/pull/1118) and join the discussion.
Current recommended way is to directly use the source code to your project.## License
[MIT](LICENSE)