mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-24 10:21:28 +01:00
Add SwiftUI + Redux
This commit is contained in:
34
Examples/SwiftUI + Redux/SwiftUIDemo/flux/states/AppState.swift
Executable file
34
Examples/SwiftUI + Redux/SwiftUIDemo/flux/states/AppState.swift
Executable file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// AppStore.swift
|
||||
// SwiftUIDemo
|
||||
//
|
||||
// Created by Thomas Ricouard on 05/06/2019.
|
||||
// Copyright © 2019 Thomas Ricouarf. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class AppState: BindableObject {
|
||||
var didChange = PassthroughSubject<AppState, Never>()
|
||||
|
||||
var usersState: UsersState
|
||||
|
||||
init(usersState: UsersState = UsersState()) {
|
||||
self.usersState = usersState
|
||||
}
|
||||
|
||||
func dispatch(action: Action) {
|
||||
usersState = UserStateReducer().reduce(state: usersState, action: action)
|
||||
didChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
let store = AppState()
|
||||
|
||||
#if DEBUG
|
||||
let sampleStore = AppState(usersState: UsersState(users: sampleData))
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user