-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
439 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
formula-coroutines/src/main/java/com/instacart/formula/coroutines/FlowFormula.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.instacart.formula.rxjava3 | ||
|
||
import com.instacart.formula.Action | ||
import com.instacart.formula.Cancelable | ||
import io.reactivex.rxjava3.core.Observable | ||
|
||
/** | ||
* Adapter which maps RxJava types to [Action] type. Take a look | ||
* at [RxAction.fromObservable]. | ||
*/ | ||
interface RxAction<Event> : Action<Event> { | ||
companion object { | ||
/** | ||
* Creates an [Action] from an [Observable] factory [create]. | ||
* | ||
* ``` | ||
* RxAction.fromObservable { locationManager.updates() }.onEvent { event -> | ||
* transition() | ||
* } | ||
* ``` | ||
*/ | ||
inline fun <Event> fromObservable( | ||
crossinline create: () -> Observable<Event> | ||
): Action<Event> { | ||
return object : RxAction<Event> { | ||
|
||
override fun observable(): Observable<Event> { | ||
return create() | ||
} | ||
|
||
override fun key(): Any = Unit | ||
} | ||
} | ||
|
||
/** | ||
* Creates an [Action] from an [Observable] factory [create]. | ||
* | ||
* ``` | ||
* RxAction.fromObservable(itemId) { repo.fetchItem(itemId) }.onEvent { event -> | ||
* transition() | ||
* } | ||
* ``` | ||
* | ||
* @param key Used to distinguish this [Action] from other actions. | ||
*/ | ||
inline fun <Event> fromObservable( | ||
key: Any?, | ||
crossinline create: () -> Observable<Event> | ||
): Action<Event> { | ||
return object : RxAction<Event> { | ||
|
||
override fun observable(): Observable<Event> { | ||
return create() | ||
} | ||
|
||
override fun key(): Any? = key | ||
} | ||
} | ||
} | ||
|
||
fun observable(): Observable<Event> | ||
|
||
override fun start(send: (Event) -> Unit): Cancelable? { | ||
val disposable = observable().subscribe(send) | ||
return Cancelable(disposable::dispose) | ||
} | ||
} |
66 changes: 2 additions & 64 deletions
66
formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxStream.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,4 @@ | ||
package com.instacart.formula.rxjava3 | ||
|
||
import com.instacart.formula.Cancelable | ||
import com.instacart.formula.Stream | ||
import io.reactivex.rxjava3.core.Observable | ||
|
||
/** | ||
* Formula [Stream] adapter to enable RxJava use. | ||
*/ | ||
interface RxStream<Event> : Stream<Event> { | ||
companion object { | ||
/** | ||
* Creates a [Stream] from an [Observable] factory [create]. | ||
* | ||
* ``` | ||
* events(RxStream.fromObservable { locationManager.updates() }) { event -> | ||
* transition() | ||
* } | ||
* ``` | ||
*/ | ||
inline fun <Event> fromObservable( | ||
crossinline create: () -> Observable<Event> | ||
): Stream<Event> { | ||
return object : RxStream<Event> { | ||
|
||
override fun observable(): Observable<Event> { | ||
return create() | ||
} | ||
|
||
override fun key(): Any = Unit | ||
} | ||
} | ||
|
||
/** | ||
* Creates a [Stream] from an [Observable] factory [create]. | ||
* | ||
* ``` | ||
* events(RxStream.fromObservable(itemId) { repo.fetchItem(itemId) }) { event -> | ||
* transition() | ||
* } | ||
* ``` | ||
* | ||
* @param key Used to distinguish this [Stream] from other streams. | ||
*/ | ||
inline fun <Event> fromObservable( | ||
key: Any?, | ||
crossinline create: () -> Observable<Event> | ||
): Stream<Event> { | ||
return object : RxStream<Event> { | ||
|
||
override fun observable(): Observable<Event> { | ||
return create() | ||
} | ||
|
||
override fun key(): Any? = key | ||
} | ||
} | ||
} | ||
|
||
fun observable(): Observable<Event> | ||
|
||
override fun start(send: (Event) -> Unit): Cancelable? { | ||
val disposable = observable().subscribe(send) | ||
return Cancelable(disposable::dispose) | ||
} | ||
} | ||
@Deprecated("use RxAction") | ||
typealias RxStream<Event> = RxAction<Event> |
Oops, something went wrong.