When building applications using Suas we start by defining the application state. Each screen, view, or view hierarchy has its own state. We use structs in Swift, data classes in Kotlin and classes in Java to represent states.

Let's consider the state needed to build the todo app example.

First, let's define a todo item. An item has a string title and a boolean that denotes if it's completed or not.

struct TodoItem {
  var title: String
  var isCompleted: Bool
data class TodoItem(val title: String, val isCompleted: Boolean)
class TodoItem {
  private final String title;
  private final boolean isCompleted;
  // constructor + getter

Our todo app will have to collect a list of those TodoItems. We need a state that collects a group of todo items.

struct TodoList {
  var todos: [TodoItem]
data class TodoList(val todos: List<TodoItem> = listOf())
class TodoList {
  private final List<TodoItem> todos;
  // constructor + getter


Note on more advanced usages

If your application contains multiple screens that are not logically or functionally tied; for example, in your todo app you might have a settings screen. In this case, instead of defining a state that contains both todo items and settings, you can head to how to build applications with multiple states.

What's Next

Now that we have the state ready, we can proceed at defining the Actions.

Related Topics

Todo app example

Other Suas architecture components

Also, check:
List of example applications built with Suas