Flux architecture implementation for Kotlin
The main goals of this is implementation is to be simple
, easy to use
and fun to work with
// Model/State
class User(val name: String)
// Actions
class SetUserAction(val user: User): Action
class ClearAction: Action
val store = Store<User?>(null) { state, action ->
when (action) {
is SetUserAction -> action.user
is ClearAction -> null
else -> state
}
}
val userNameSelector = store.selector { it?.name }
store.dispatch(SetUserAction(User("John Doe")))
Assertions.assertEquals("John Doe", userNameSelector())
store.dispatch(ClearAction())
Assertions.assertEquals(null, userNameSelector())
You can find more examples at src/test/kotlin/fluk/core/usecases
- Dispatch mechanism
- Middlewares
- Subscribers
- Value watchers
- Selectors
- Time travel mechanism
- Thread safe store