Created
September 7, 2020 20:30
-
-
Save azamsharp/37ad76990cf618f2a2cfc456c986273e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Store.swift | |
typealias ActionCreator = (_ dispatch: @escaping (Action) -> ()) -> () | |
func getMovies() -> ActionCreator { | |
return { dispatch in | |
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { | |
dispatch(.populateMovies([Movie(title: "ABC")])) | |
} | |
} | |
} | |
class Store: ObservableObject { | |
var reducer: Reducer | |
@Published private (set) var appState: AppState | |
init(appState: AppState, reducer: Reducer) { | |
self.appState = appState | |
self.reducer = reducer | |
} | |
func dispatch(_ dispatch: ActionCreator) { | |
// how to send the movies to the reducer to update the state | |
//self.reducer.update(&appState, dispatch) | |
} | |
} | |
// ContentView: | |
store.dispatch(getMovies()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment