Skip to content

Commit eedca1a

Browse files
committed
add multiple stores example
1 parent 2971626 commit eedca1a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docs/media/multipleStores.png

13.7 KB
Loading

docs/store.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,33 @@ private sealed interface Msg {
696696
// ...
697697
}
698698
```
699+
700+
## Using Multiple Stores on a Single Screen
701+
702+
Complex screen logic often benefits from being divided into meaningful parts handled by independent Stores. This modularity improves maintainability and clarity.
703+
For example, consider the following diagram:
704+
705+
![MultipleStores](media/multipleStores.png)
706+
707+
One way to organize the interaction between these Stores is as follows:
708+
709+
```kotlin
710+
internal class StoreA(private val storeFactory: StoreFactory) {
711+
712+
fun create(
713+
stateB: Flow<StateB>,
714+
partStateC: Flow<PartStateC>, // <- If you don't need full StateC, you can create PartStateC to abstract only required data
715+
partStateD: Flow<PartStateD>
716+
): StoreA =
717+
object : StoreA, Store<Intent, State, Nothing> by storeFactory.create(
718+
name = "StoreA",
719+
initialState = State(),
720+
bootstrapper = createBootstrapper(stateB, partStateC, partStateD), // <- Bootstrapper (or Executor) starts collecting required data
721+
executorFactory = ::ExecutorImpl,
722+
reducer = ReducerImpl
723+
) {
724+
}
725+
726+
// ...
727+
}
728+
```

0 commit comments

Comments
 (0)