Skip to content

Commit

Permalink
Deprecate Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc committed Apr 8, 2019
1 parent dcea1bb commit 09c7494
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 147 deletions.
3 changes: 0 additions & 3 deletions Rx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2995,7 +2995,6 @@
C8C217D71CB710200038A2E6 /* UICollectionView+RxTests.swift in Sources */,
C83509451C38706E0027C24C /* Observable.Extensions.swift in Sources */,
C835093B1C38706E0027C24C /* RXObjCRuntime+Testing.m in Sources */,
C83509641C38706E0027C24C /* VariableTest.swift in Sources */,
C83509461C38706E0027C24C /* PrimitiveHotObservable.swift in Sources */,
C820A9861EB4FB5B00D431BC /* Observable+DebugTests.swift in Sources */,
C820AA021EB5134000D431BC /* Observable+DelaySubscriptionTests.swift in Sources */,
Expand Down Expand Up @@ -3132,7 +3131,6 @@
C8B2908A1C94D64700E923D0 /* RxTest+Controls.swift in Sources */,
B44D73EC1EE6D4A300EBFBE8 /* UIViewController+RxTests.swift in Sources */,
C820A9671EB4F39500D431BC /* Observable+SubscribeOnTests.swift in Sources */,
C8350A181C38756A0027C24C /* VariableTest.swift in Sources */,
C820A9C71EB50A4200D431BC /* Observable+SkipWhileTests.swift in Sources */,
C8BAA78E1E34F8D400EEC727 /* RecursiveLockTest.swift in Sources */,
C83509EF1C3875580027C24C /* PrimitiveHotObservable.swift in Sources */,
Expand Down Expand Up @@ -3368,7 +3366,6 @@
927A78C92117BCB400A45638 /* NSTextView+RxTests.swift in Sources */,
C820A9CC1EB50A7100D431BC /* Observable+ElementAtTests.swift in Sources */,
C83509D11C38752E0027C24C /* RuntimeStateSnapshot.swift in Sources */,
C8350A221C38756B0027C24C /* VariableTest.swift in Sources */,
C8A53AE71F09292A00490535 /* Completable+AndThen.swift in Sources */,
1E9DA0C722006858000EB80A /* Synchronized.swift in Sources */,
C83509D21C3875380027C24C /* RXObjCRuntime+Testing.m in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions RxCocoa/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public func driveOnScheduler(_ scheduler: SchedulerType, action: () -> Void) {
SharingScheduler.mock(scheduler: scheduler, action: action)
}

@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
extension Variable {
/// Converts `Variable` to `SharedSequence` unit.
///
Expand Down Expand Up @@ -407,6 +408,7 @@ extension Reactive where Base: UISegmentedControl {

import RxSwift

@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
extension Variable {
/// Converts `Variable` to `Driver` trait.
///
Expand All @@ -430,6 +432,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingSt
- parameter variable: Target variable for sequence elements.
- returns: Disposable object that can be used to unsubscribe the observer from the variable.
*/
@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
public func drive(_ variable: Variable<E>) -> Disposable {
MainScheduler.ensureRunningOnMainThread(errorMessage: errorMessage)
return self.drive(onNext: { e in
Expand All @@ -444,6 +447,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingSt
- parameter variable: Target variable for sequence elements.
- returns: Disposable object that can be used to unsubscribe the observer from the variable.
*/
@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
public func drive(_ variable: Variable<E?>) -> Disposable {
MainScheduler.ensureRunningOnMainThread(errorMessage: errorMessage)
return self.drive(onNext: { e in
Expand All @@ -452,6 +456,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingSt
}
}

@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
extension ObservableType {
/**
Creates new subscription and sends elements to variable.
Expand Down
5 changes: 1 addition & 4 deletions RxSwift/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ extension ObservableType {
/// * It has an inconsistent memory management model compared to other parts of RxSwift (completes on `deinit`).
///
/// Once plans are finalized, official availability attribute will be added in one of upcoming versions.
@available(*, deprecated, message: "Variable is deprecated. Please use `BehaviorRelay` as a replacement.")
public final class Variable<Element> {

public typealias E = Element
Expand Down Expand Up @@ -209,10 +210,6 @@ public final class Variable<Element> {
///
/// - parameter value: Initial variable value.
public init(_ value: Element) {
#if DEBUG
DeprecationWarner.warnIfNeeded(.variable)
#endif

self._value = value
self._subject = BehaviorSubject(value: value)
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/RxCocoaTests/Driver+Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ extension DriverTest {
}

func testVariableAsDriver() {
var hotObservable: Variable<Int>? = Variable(1)
var hotObservable: BehaviorRelay<Int>? = BehaviorRelay(value: 1)
let xs = Driver.zip(hotObservable!.asDriver(), Driver.of(0, 0)) { optInt, _ in
return optInt
}

let results = subscribeTwiceOnBackgroundSchedulerAndOnlyOneSubscription(xs) {
hotObservable?.value = 1
hotObservable?.value = 2
hotObservable?.accept(1)
hotObservable?.accept(2)
hotObservable = nil
}

Expand Down
28 changes: 0 additions & 28 deletions Tests/RxCocoaTests/Observable+BindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,6 @@ extension ObservableBindTest {
}
}

// MARK: bind(to:) variable

extension ObservableBindTest {
func testBindToVariable() {
let variable = Variable<Int>(0)

_ = Observable.just(1).bind(to: variable)

XCTAssertEqual(variable.value, 1)
}

func testBindToOptionalVariable() {
let variable = Variable<Int?>(0)

_ = (Observable.just(1) as Observable<Int>).bind(to: variable)

XCTAssertEqual(variable.value, 1)
}

func testBindToVariableNoAmbiguity() {
let variable = Variable<Int?>(0)

_ = Observable.just(1).bind(to: variable)

XCTAssertEqual(variable.value, 1)
}
}

// MARK: bind(to:) publish relay

extension ObservableBindTest {
Expand Down
109 changes: 0 additions & 109 deletions Tests/RxSwiftTests/VariableTest.swift

This file was deleted.

0 comments on commit 09c7494

Please sign in to comment.