Skip to content

Commit

Permalink
Implement new as-based API (#141)
Browse files Browse the repository at this point in the history
* WIP as() converters

* Move kotlin to use the new APIs

* Documentation pass

* Create matching extension functions, deprecate old

* Update kotlin tests with new extensions

* Gradle 4.3.1

* Lower back to 4.2.1 due to error-prone plugin

Compatibility issues

* Make checkstyle happy about imports and lines

* Update kotlin, error prone, nullaway, checker

* Gradle 4.3.1 again, error prone and apt plugins to 0.0.13
  • Loading branch information
ZacSweers authored Dec 4, 2017
1 parent 16a517f commit deab8fb
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 107 deletions.
3 changes: 2 additions & 1 deletion android/autodispose-android-archcomponents-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ dependencies {

tasks.withType(JavaCompile) {
options.compilerArgs += ["-Xep:NullAway:ERROR",
"-XepOpt:NullAway:AnnotatedPackages=com.uber"]
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-Xep:RestrictTo:OFF"]
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 changes: 2 additions & 1 deletion android/autodispose-android-archcomponents/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ dependencies {

tasks.withType(JavaCompile) {
options.compilerArgs += ["-Xep:NullAway:ERROR",
"-XepOpt:NullAway:AnnotatedPackages=com.uber"]
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-Xep:RestrictTo:OFF"]
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
4 changes: 3 additions & 1 deletion android/autodispose-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ dependencies {
}

tasks.withType(JavaCompile) {
options.compilerArgs += ["-Xep:NullAway:ERROR", "-XepOpt:NullAway:AnnotatedPackages=com.uber"]
options.compilerArgs += ["-Xep:NullAway:ERROR",
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-Xep:RestrictTo:OFF"]
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.uber.autodispose.kotlin

import com.uber.autodispose.AutoDispose
import com.uber.autodispose.AutoDispose.ScopeHandler
import com.uber.autodispose.CompletableSubscribeProxy
import com.uber.autodispose.FlowableSubscribeProxy
import com.uber.autodispose.LifecycleScopeProvider
Expand All @@ -33,114 +32,314 @@ import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.annotations.CheckReturnValue
import kotlin.DeprecationLevel.WARNING

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.with] + [ScopeHandler.forFlowable]
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(scope)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposeWith(scope: Maybe<*>): FlowableSubscribeProxy<T>
= this.to(AutoDispose.with(scope).forFlowable())
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable]
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(scope)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposeWith(scope: Maybe<*>): ObservableSubscribeProxy<T>
= this.to(AutoDispose.with(scope).forObservable())
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle]
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(scope)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Single<T>.autoDisposeWith(scope: Maybe<*>): SingleSubscribeProxy<T>
= this.to(AutoDispose.with(scope).forSingle())
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe]
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(scope)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposeWith(scope: Maybe<*>): MaybeSubscribeProxy<T>
= this.to(AutoDispose.with(scope).forMaybe())
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.with] + [ScopeHandler.forCompletable]
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(scope)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun Completable.autoDisposeWith(scope: Maybe<*>): CompletableSubscribeProxy
= this.to(AutoDispose.with(scope).forCompletable())
= this.`as`(AutoDispose.autoDisposable<Any>(scope))

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.with] + [ScopeHandler.forFlowable]
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposeWith(provider: ScopeProvider): FlowableSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forFlowable())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable]
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposeWith(provider: ScopeProvider): ObservableSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forObservable())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle]
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Single<T>.autoDisposeWith(provider: ScopeProvider): SingleSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forSingle())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe]
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposeWith(provider: ScopeProvider): MaybeSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forMaybe())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.with] + [ScopeHandler.forCompletable]
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun Completable.autoDisposeWith(provider: ScopeProvider): CompletableSubscribeProxy
= this.to(AutoDispose.with(provider).forCompletable())
= this.`as`(AutoDispose.autoDisposable<Any>(provider))

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.with]+ [ScopeHandler.forFlowable]
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposeWith(
provider: LifecycleScopeProvider<*>): FlowableSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forFlowable())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable]
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposeWith(
provider: LifecycleScopeProvider<*>): ObservableSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forObservable())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle]
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Single<T>.autoDisposeWith(
provider: LifecycleScopeProvider<*>): SingleSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forSingle())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe]
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposeWith(provider: LifecycleScopeProvider<*>): MaybeSubscribeProxy<T>
= this.to(AutoDispose.with(provider).forMaybe())
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.with]+ [ScopeHandler.forCompletable]
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@Deprecated(
level = WARNING,
message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.",
replaceWith = ReplaceWith("autoDisposable(provider)",
"com.uber.autodispose.kotlin.autoDisposable")
)
@CheckReturnValue
inline fun Completable.autoDisposeWith(
provider: LifecycleScopeProvider<*>): CompletableSubscribeProxy
= this.to(AutoDispose.with(provider).forCompletable())
= this.`as`(AutoDispose.autoDisposable<Any>(provider))

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposable(scope: Maybe<*>): FlowableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposable(scope: Maybe<*>): ObservableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Single<T>.autoDisposable(scope: Maybe<*>): SingleSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposable(scope: Maybe<*>): MaybeSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(scope))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun Completable.autoDisposable(scope: Maybe<*>): CompletableSubscribeProxy
= this.`as`(AutoDispose.autoDisposable<Any>(scope))

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposable(provider: ScopeProvider): FlowableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposable(provider: ScopeProvider): ObservableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Single<T>.autoDisposable(provider: ScopeProvider): SingleSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposable(provider: ScopeProvider): MaybeSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun Completable.autoDisposable(provider: ScopeProvider): CompletableSubscribeProxy
= this.`as`(AutoDispose.autoDisposable<Any>(provider))

/**
* Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable]
*
*/
@CheckReturnValue
inline fun <T> Flowable<T>.autoDisposable(
provider: LifecycleScopeProvider<*>): FlowableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Observable<T>.autoDisposable(
provider: LifecycleScopeProvider<*>): ObservableSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Single.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Single<T>.autoDisposable(
provider: LifecycleScopeProvider<*>): SingleSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun <T> Maybe<T>.autoDisposable(provider: LifecycleScopeProvider<*>): MaybeSubscribeProxy<T>
= this.`as`(AutoDispose.autoDisposable(provider))

/**
* Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable]
*/
@CheckReturnValue
inline fun Completable.autoDisposable(
provider: LifecycleScopeProvider<*>): CompletableSubscribeProxy
= this.`as`(AutoDispose.autoDisposable<Any>(provider))
Loading

0 comments on commit deab8fb

Please sign in to comment.