mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-27 02:58:43 +02:00
Update
This commit is contained in:
34
Other Projects/SwiftUI + Redux/SwiftUIDemo/flux/states/AppState.swift
Executable file
34
Other Projects/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
|
||||
|
||||
|
||||
11
Other Projects/SwiftUI + Redux/SwiftUIDemo/flux/states/FluxState.swift
Executable file
11
Other Projects/SwiftUI + Redux/SwiftUIDemo/flux/states/FluxState.swift
Executable file
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// FluxState.swift
|
||||
// SwiftUIDemo
|
||||
//
|
||||
// Created by Thomas Ricouard on 05/06/2019.
|
||||
// Copyright © 2019 Thomas Ricouarf. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol FluxState { }
|
||||
20
Other Projects/SwiftUI + Redux/SwiftUIDemo/flux/states/UsersState.swift
Executable file
20
Other Projects/SwiftUI + Redux/SwiftUIDemo/flux/states/UsersState.swift
Executable file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// UsersStore.swift
|
||||
// SwiftUIDemo
|
||||
//
|
||||
// Created by Thomas Ricouard on 04/06/2019.
|
||||
// Copyright © 2019 Thomas Ricouarf. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
struct UsersState: FluxState {
|
||||
var users: [User]
|
||||
var isEditingUser = false
|
||||
|
||||
init(users: [User] = []) {
|
||||
self.users = users
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user