-
Notifications
You must be signed in to change notification settings - Fork 202
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
1 parent
8998792
commit 0598289
Showing
52 changed files
with
63,181 additions
and
234 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
5 changes: 5 additions & 0 deletions
5
...ental/market/src/commonMain/kotlin/org/mobilenativefoundation/market/MarketContributor.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,5 @@ | ||
package org.mobilenativefoundation.market | ||
|
||
interface MarketContributor<K : Any> { | ||
fun contribute(key: K) | ||
} |
30 changes: 30 additions & 0 deletions
30
...ket/src/commonMain/kotlin/org/mobilenativefoundation/market/impl/RealMarketContributor.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,30 @@ | ||
package org.mobilenativefoundation.market.impl | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import org.mobilenativefoundation.market.Market | ||
import org.mobilenativefoundation.market.MarketContributor | ||
import org.mobilenativefoundation.store.store5.Store | ||
import org.mobilenativefoundation.store.store5.impl.extensions.fresh | ||
|
||
class RealMarketContributor<K : Any, O : Any, A : Market.Action, D : Market.Dispatcher<A>>( | ||
coroutineDispatcher: CoroutineDispatcher, | ||
private val store: Store<K, O>, | ||
private val marketDispatcher: D, | ||
private val marketActionFactory: MarketActionFactory<O, A> | ||
): MarketContributor<K> { | ||
private val coroutineScope = CoroutineScope(coroutineDispatcher) | ||
|
||
override fun contribute(key: K) { | ||
coroutineScope.launch { | ||
val storeOutput = store.fresh(key) | ||
val marketAction = marketActionFactory.create(storeOutput) | ||
marketDispatcher.dispatch(marketAction) | ||
} | ||
} | ||
} | ||
|
||
fun interface MarketActionFactory<O : Any, A : Market.Action> { | ||
fun create(storeOutput: O): A | ||
} |
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
42 changes: 30 additions & 12 deletions
42
.../warehouse/src/commonMain/kotlin/org/mobilenativefoundation/market/warehouse/Warehouse.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,28 +1,46 @@ | ||
package org.mobilenativefoundation.market.warehouse | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.* | ||
import org.mobilenativefoundation.market.Market | ||
|
||
|
||
interface Warehouse<S : Warehouse.State, A : Warehouse.Action> { | ||
|
||
interface Warehouse<S : Warehouse.State, A : Warehouse.Action, AA: Warehouse.Action.Async> { | ||
val state: StateFlow<S> | ||
fun dispatch(action: A) | ||
fun dispatch(worker: Worker<S, A>) | ||
fun dispatch(action: AA) | ||
fun <D : Any> subscribe(selector: Selector<S, D>): Flow<D> | ||
|
||
interface Action { | ||
interface Async: Action | ||
interface Async : Action | ||
} | ||
|
||
interface State | ||
fun interface Worker<S : State, A : Action> { | ||
fun work(getState: () -> S, dispatch: (action: A) -> Unit) | ||
} | ||
|
||
fun interface Selector<S : State, D : Any> { | ||
fun select(state: S): D | ||
} | ||
} | ||
|
||
class RealWarehouse<S : Warehouse.State, A : Warehouse.Action, MS : Market.State, M : Market<MS>>( | ||
coroutineDispatcher: CoroutineDispatcher, | ||
private val market: M, | ||
private val extractor: (MS) -> S, | ||
private val actionHandler: (A, MS) -> Unit | ||
) : Warehouse<S, A> { | ||
|
||
fun interface Middleware<A: Action> { | ||
fun apply(action: A, next: (action: A) -> Unit) | ||
private val coroutineScope = CoroutineScope(coroutineDispatcher) | ||
|
||
override val state: StateFlow<S> = market.state.map { | ||
extractor(it) | ||
}.stateIn(coroutineScope, SharingStarted.Eagerly, extractor(market.state.value)) | ||
|
||
|
||
override fun <D : Any> subscribe(selector: Warehouse.Selector<S, D>): Flow<D> = | ||
state.map { selector.select(it) } | ||
|
||
override fun dispatch(action: A) { | ||
actionHandler(action, market.state.value) | ||
} | ||
} | ||
} |
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
7 changes: 6 additions & 1 deletion
7
...n/org/mobilenativefoundation/sample/octonaut/android/app/circuit/OctonautScreenFactory.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,8 +1,13 @@ | ||
package org.mobilenativefoundation.sample.octonaut.android.app.circuit | ||
|
||
import me.tatarka.inject.annotations.Inject | ||
import org.mobilenativefoundation.sample.octonaut.xplat.feat.homeTab.api.HomeTab | ||
import org.mobilenativefoundation.sample.octonaut.xplat.foundation.di.api.UserScope | ||
|
||
@Inject | ||
@UserScope | ||
class OctonautScreenFactory : ScreenFactory | ||
class OctonautScreenFactory( | ||
private val homeTab: HomeTab | ||
) : ScreenFactory { | ||
override fun homeTab(): HomeTab = homeTab | ||
} |
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
4 changes: 3 additions & 1 deletion
4
...in/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/circuit/ScreenFactory.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,6 +1,8 @@ | ||
package org.mobilenativefoundation.sample.octonaut.android.app.circuit | ||
|
||
interface ScreenFactory { | ||
import org.mobilenativefoundation.sample.octonaut.xplat.feat.homeTab.api.HomeTab | ||
|
||
interface ScreenFactory { | ||
fun homeTab(): HomeTab | ||
} | ||
|
Oops, something went wrong.