Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created September 7, 2020 20:30
Show Gist options
  • Save azamsharp/37ad76990cf618f2a2cfc456c986273e to your computer and use it in GitHub Desktop.
Save azamsharp/37ad76990cf618f2a2cfc456c986273e to your computer and use it in GitHub Desktop.
// 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