Redux-like state container in SwiftUI. Reducer and Actions

…about user actions which lead to state mutations. Action is a simple enum or composition of enums describing a change of the state. For example, set loading value during data fetch, assign fetched repositories to the state property. Let’s take a loo…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sergey Leschev

...about user actions which lead to state mutations. Action is a simple enum or composition of enums describing a change of the state. For example, set loading value during data fetch, assign fetched repositories to the state property. Let’s take a look at the example code for Action enum.

enum AppAction {
    case search(query: String)
    case setSearchResult(repos: [Repo])
}

Reducer is a function that takes current state, applies Action to the state, and generates a new state. Generally, reducer or composition of reducers is the single place where your app should mutate the state. The fact that the only one function can modify the whole app state is super simple, debuggable, and testable. Here is an example of reduce function.

typealias Reducer<State, Action> = (inout State, Action) -> Void

func appReducer(state: inout AppState, action: AppAction) {
    switch action {
    case let .setSearchResults(repos):
        state.searchResult = repos
    case let .search(query):
        break
    }
}

Contacts
I have a clear focus on time-to-market and don't prioritize technical debt. And I took part in the Pre-Sale/RFX activity as a System Architect, assessment efforts for Mobile (iOS-Swift, Android-Kotlin), Frontend (React-TypeScript) and Backend (NodeJS-.NET-PHP-Kafka-SQL-NoSQL). And I also formed the work of Pre-Sale as a CTO from Opportunity to Proposal via knowledge transfer to Successful Delivery.

🛩️ #startups #management #cto #swift #typescript #database
📧 Email: sergey.leschev@gmail.com
👋 LinkedIn: https://www.linkedin.com/in/sergeyleschev/
👋 LeetCode: https://leetcode.com/sergeyleschev/
👋 Twitter: https://twitter.com/sergeyleschev
👋 Github: https://github.com/sergeyleschev
🌎 Website: https://sergeyleschev.github.io


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sergey Leschev


Print Share Comment Cite Upload Translate Updates
APA

Sergey Leschev | Sciencx (2023-02-11T15:42:58+00:00) Redux-like state container in SwiftUI. Reducer and Actions. Retrieved from https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/

MLA
" » Redux-like state container in SwiftUI. Reducer and Actions." Sergey Leschev | Sciencx - Saturday February 11, 2023, https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/
HARVARD
Sergey Leschev | Sciencx Saturday February 11, 2023 » Redux-like state container in SwiftUI. Reducer and Actions., viewed ,<https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/>
VANCOUVER
Sergey Leschev | Sciencx - » Redux-like state container in SwiftUI. Reducer and Actions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/
CHICAGO
" » Redux-like state container in SwiftUI. Reducer and Actions." Sergey Leschev | Sciencx - Accessed . https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/
IEEE
" » Redux-like state container in SwiftUI. Reducer and Actions." Sergey Leschev | Sciencx [Online]. Available: https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/. [Accessed: ]
rf:citation
» Redux-like state container in SwiftUI. Reducer and Actions | Sergey Leschev | Sciencx | https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-reducer-and-actions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.