Skip to content
Miguel Panelo edited this page Feb 10, 2019 · 3 revisions

An action is a representation of anything that requires interaction from the client. It contains necessary input to present this interaction.

Kaskade only accepts actions with the type Action which is an empty interface that exists only for typing. This means that all the actions that you have for a Kaskade must inherit from a class with the type of Action which sealed classes does very well.

With the todo example we represent the actions as follows:

sealed class TodoAction : Action {
    object Refresh : TodoAction()
    data class Delete(val position: Int, val todoItem: TodoItem) : TodoAction()
    data class Add(val todoItem: TodoItem) : TodoAction()
    data class Update(val position: Int, val todoItem: TodoItem) : TodoAction()
}

For actions that does not require information from the client it can simply be represented as an object.

object Refresh : TodoAction()

Ideally actions should be data classes but you can also use normal classes. The important thing here is the typing as it is used to determine which reducer should be executed with the action type.

Executing Actions

kaskade.process(TodoAction.Refresh)

Kaskade has a method process which takes a type of A: Action that executes an action and finds the appropriate Reducer to come up with a new State