O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Actions

Actions are structs that conform to the ActionType protocol from the Delta library. ActionType is used when we want to make modifications to the store's State. All changes to the Store object go through this type. Let's examine one example:

import Delta struct UpdateTodoAction: ActionType {     let todo: Todo     func reduce(state: State) -> State {         state.todos.value = state.todos.value.map {             todo in             guard todo == self.todo else { return todo }             return Todo(todoId: todo.todoId,                         name: self.todo.name,                         description: self.todo.description,                         notes: self.todo.notes,                         completed: self.todo.completed,                         synced: !todo.synced,                         selected: todo.selected)         }         return state     } } 

In our manager, we had a call like this:

 store.dispatch(UpdateTodoAction(todo: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required