Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import RxRelay
  2. import RxSwift
  3.  
  4. @propertyWrapper
  5. public struct BehaviorRelayWrapping<T> {
  6. private let subject: BehaviorRelay<T>
  7.  
  8. // MARK: PropertyWrapper
  9.  
  10. public let wrappedValue: Observable<T>
  11.  
  12. public init(value: T) {
  13. subject = BehaviorRelay(value: value)
  14. wrappedValue = subject.asObservable()
  15. }
  16.  
  17. // MARK: BehaviorRelay
  18.  
  19. public func accept(_ event: T) {
  20. subject.accept(event)
  21. }
  22. }
  23.  
  24. @propertyWrapper
  25. public struct PublishRelayWrapping<T> {
  26. private let subject: PublishRelay<T>
  27.  
  28. // MARK: PropertyWrapper
  29.  
  30. public let wrappedValue: Observable<T>
  31.  
  32. public init() {
  33. subject = PublishRelay<T>()
  34. wrappedValue = subject.asObservable()
  35. }
  36.  
  37. // MARK: PublishRelay
  38.  
  39. public func accept(_ event: T) {
  40. subject.accept(event)
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement