RxSwift source code and pattern analysis 1: basic class

Encapsulation, Transformation and Processing

// Represents a push style sequence.

public protocol ObservableType : ObservableConvertibleType {

      func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == E

}

 

/// It represents a push style sequence.

public class Observable<Element> : ObservableType {

    public typealias E = Element

    

    public func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == E {

        rxAbstractMethod()

    }

    

    public func asObservable() -> Observable<E> {

        return self

    }

 

    /// Optimizations for map operator

    internal func composeMap<R>(_ transform: @escaping (Element) throws -> R) -> Observable<R> {

        return _map(source: self, transform: transform)

    }

}

 

public protocol ObserverType {

    associatedtype E

    func on(_ event: Event<E>)

}

 

public enum Event<Element> {

    case next(Element)

    case error(Swift.Error)

    case completed

}

 

public struct Reactive<Base> {

    public let base: Base

    public init(_ base: Base) {

        self.base = base

    }

}

 

public struct Binder<Value>: ObserverType

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325770589&siteId=291194637