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
}
}

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
}
}

It results in exact same Store instance as the previous example.