Redux-like state container in SwiftUI. Unidirectional flow.

…about data flow now.

Every view has a read-only access to the state via store object. Views can send actions to the store object. Reducer modifies the state, and then SwiftUI notifies all the views about state changes. SwiftUI has a super-efficien…


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

...about data flow now.

Every view has a read-only access to the state via store object. Views can send actions to the store object. Reducer modifies the state, and then SwiftUI notifies all the views about state changes. SwiftUI has a super-efficient diffing algorithm that’s why diffing of the whole app state and updating changed views works so fast. Let’s modify our store object to support sending actions.

final class Store<State, Action>: ObservableObject {
    @Published private(set) var state: State

    private let reducer: Reducer<State, Action>

    init(initialState: State, reducer: @escaping Reducer<State, Action>) {
        self.state = initialState
        self.reducer = reducer
    }

    func send(_ action: Action) {
        reducer(&state, action)
    }
}

State -> View -> Action -> State -> View

This architecture revolves around a strict unidirectional data flow. It means that all the data in the application follows the same pattern, making the logic of your app more predictable and easier to understand.

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:46:13+00:00) Redux-like state container in SwiftUI. Unidirectional flow.. Retrieved from https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-unidirectional-flow/

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

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.