-
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
27 changed files
with
448 additions
and
354 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
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) | ||
} | ||
} |
Oops, something went wrong.