 import RxSwift
 import RxCocoa
 
-/// A get-only `Variable` that is equivalent to ReactiveSwift's `Property`.
+/// A get-only `BehaviorRelay` that works similar to ReactiveSwift's `Property`.
 ///
 /// - Note:
-/// This will send `.completed` when deallocated, just like `Variable` but not like `BehaviorRelay`.
-/// Thus, this class doesn't conform to `ObservableConvertibleType` for avoiding this being captured accidentally.
+/// From ver 0.3.0, this class will no longer send `.completed` when deallocated.
 ///
 /// - SeeAlso:
 ///     https://github.com/ReactiveCocoa/ReactiveSwift/blob/1.1.0/Sources/Property.swift


    public typealias E = Element

    private let _variable: Variable<E>
    private let _disposeBag: DisposeBag?

    /// Gets current value.
    public var value: E {
        get {
            return _variable.value
        }
    }

    /// Initializes with initial value.
    public init(_ value: E) {
        _variable = Variable(value)
        _disposeBag = nil
    }

    /// Initializes with `Variable` and captures it.
    public init(capturing variable: Variable<E>) {
        _variable = variable
        _disposeBag = nil
    }

    /// Initializes with `Variable` but not capturing it.
    public convenience init(_ variable: Variable<E>) {
        self.init(unsafeObservable: variable.asObservable())
    }

    /// Initializes with `BehaviorRelay` but not capturing it.
    public convenience init(_ behaviorRelay: BehaviorRelay<E>) {
        self.init(unsafeObservable: behaviorRelay.asObservable())
    }

    /// Initializes with `Observable` that must send at least one value synchronously.

    /// - Warning:
    /// If `unsafeObservable` sends multiple values synchronously,
    /// the last value will be treated as initial value of `Property`.
    public convenience init(unsafeObservable: Observable<E>) {
        let observable = unsafeObservable.share(replay: 1, scope: .whileConnected)
        var initial: E? = nil

        let initialDisposable = observable
            .subscribe(onNext: { initial = $0 })

        guard let initial_ = initial else {
            fatalError("An unsafeObservable promised to send at least one value. Received none.")
        }

        self.init(initial: initial_, then: observable)

        initialDisposable.dispose()
    }

    /// Initializes with `initial` element and then `observable`.
