Add Async image loading

This commit is contained in:
Ivan Vorobei
2019-06-06 22:24:34 +03:00
parent dbabd124fb
commit bcedea412a
914 changed files with 164 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
import SwiftUI
import Combine
public final class Store<StateType>: BindableObject where StateType: StateMachine {
private let initialState: StateType
private var subsequentStates: [StateType] = []
public let didChange = PassthroughSubject<Void, Never>()
public init(state: StateType) {
initialState = state
}
var allStates: [StateType] {
[[initialState], subsequentStates].flatMap({ $0 })
}
var stateCount: Int {
1 + subsequentStates.count
}
var currentStateIndex: Int = 0 {
didSet {
withAnimation {
didChange.send(())
}
}
}
/// The current state of the store. This will update as time traveling occurs.
public var state: StateType {
allStates[currentStateIndex]
}
/// Dispatches an event to be applied to the current state.
public func dispatch(event: StateType.Event) {
var newState = state
newState.update(with: event)
subsequentStates.append(newState)
currentStateIndex = stateCount - 1
}
}