Reactive.swift 1006 B

12345678910111213141516171819202122232425262728293031323334
  1. /// Describes a provider of reactive extensions.
  2. ///
  3. /// - note: `ReactiveExtensionsProvider` does not indicate whether a type is
  4. /// reactive. It is intended for extensions to types that are not owned
  5. /// by the module in order to avoid name collisions and return type
  6. /// ambiguities.
  7. public protocol ReactiveExtensionsProvider: class {}
  8. extension ReactiveExtensionsProvider {
  9. /// A proxy which hosts reactive extensions for `self`.
  10. public var reactive: Reactive<Self> {
  11. return Reactive(self)
  12. }
  13. /// A proxy which hosts static reactive extensions for the type of `self`.
  14. public static var reactive: Reactive<Self>.Type {
  15. return Reactive<Self>.self
  16. }
  17. }
  18. /// A proxy which hosts reactive extensions of `Base`.
  19. public struct Reactive<Base> {
  20. /// The `Base` instance the extensions would be invoked with.
  21. public let base: Base
  22. // Construct a proxy.
  23. //
  24. // - parameters:
  25. // - base: The object to be proxied.
  26. fileprivate init(_ base: Base) {
  27. self.base = base
  28. }
  29. }