Redux-like state container in SwiftUI. Unidirectional flow.

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-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:?[email protected]

?? LinkedIn:?https://www.dhirubhai.net/in/sergeyleschev/

?? LeetCode:?https://leetcode.com/sergeyleschev/

?? Twitter:?https://twitter.com/sergeyleschev

?? Github:?https://github.com/sergeyleschev

?? Website:?https://sergeyleschev.github.io

?? DEV Community: https://dev.to/sergeyleschev

?? Reddit: https://reddit.com/user/sergeyleschev

?? Quora: https://quora.com/sergey-leschev

?? Medium: https://medium.com/@sergeyleschev

要查看或添加评论,请登录

Siarhei Liashchou的更多文章

社区洞察

其他会员也浏览了