-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathReactive.swift
58 lines (47 loc) · 1.21 KB
/
Reactive.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Reactive.swift
// Rx
//
// Created by Yury Korolev on 5/2/16.
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
/**
Use `Reactive` proxy as customization point for constrained protocol extensions.
General pattern would be:
// 1. Extend Reactive protocol with constrain on Self
// Read as: Reactive Extension where Self is a SomeType
extension Reactive where Self: SomeType {
// 2. Put any specific reactive extension for SomeType here
}
With this approach we can have more specialized methods and properties using
`Self` and not just specialized on common base type.
*/
public struct Reactive<Base> {
/**
Base object to extend.
*/
public let base: Base
/**
Creates extensions with base object.
- parameter base: Base object.
*/
public init(_ base: Base) {
self.base = base
}
}
/**
A type that has reactive extensions.
*/
public protocol ReactiveCompatible {
associatedtype CompatibleType
var rx: Reactive<CompatibleType> { get }
}
public extension ReactiveCompatible {
public var rx: Reactive<Self> {
return Reactive(self)
}
}
/**
Extend NSObject with `rx` proxy.
*/
extension NSObject: ReactiveCompatible { }