buildStore
Provides a DSL for building a Store.
Example of usage:
fun createAppStore(isDebugVersion: Boolean) = buildStore {
AppState() reducedBy ::appReducer // sets an initial state and a root reducer
middlewares { // adds a list of middlewares in a given order
+thunkMiddleware
if (isDebugVersion) +logMiddleware()
}
closure { // accumulates given closure elements into single one
+DispatchCoroutineScope(MainScope())
+GlobalKoinDI
}
}
Content copied to clipboard
It is possible to split closure and middlewares into multiple blocks like this:
fun createAppStore(isDebugVersion: Boolean) = buildStore {
AppState() reducedBy ::appReducer
middlewares {
+thunkMiddleware
}
closure {
+DispatchCoroutineScope(MainScope())
}
middlewares {
if (isDebugVersion) +logMiddleware()
}
closure {
+GlobalKoinDI
}
}
Content copied to clipboard
It results in exact same Store instance as the previous example.