Guest User

Untitled

a guest
Dec 11th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. final class AppSaga {
  2. typealias Effect = Redux.Saga.Effect
  3.  
  4. /// The app's saga branches.
  5. static func sagas(_ api: AppRepositoryType) -> [Effect<AppState, Any>] {
  6. return [
  7. Redux.Saga.Effect.takeLatest(
  8. paramExtractor: self.autocompleteParam,
  9. effectCreator: {self.verboseAutocompleteSaga(api, $0)},
  10. options: .default())
  11. ]
  12. }
  13.  
  14. /// Extract the autocomplete query from an action.
  15. static func autocompleteParam(_ action: AppAction) -> String? {
  16. switch action {
  17. case .updateAutocompleteInput(let input): return input
  18. default: return nil
  19. }
  20. }
  21.  
  22. /// Verbose saga to demonstrate full use of helper functions.
  23. static func verboseAutocompleteSaga(_ api: AppRepositoryType, _ input: String)
  24. -> Redux.Saga.Effect<AppState, Any>
  25. {
  26. /// Create an Effect wrapper from the input string.
  27. let inputEffect = Redux.Saga.Effect<AppState, String>.just(input)
  28.  
  29. /// Create a CallEffect to invoke the search API on the query.
  30. let callEffect = Redux.Saga.Effect
  31. .call(with: inputEffect, callCreator: api.searchITunes)
  32.  
  33. /// Create a PutEffect to deposit search results into the Redux Store.
  34. return Redux.Saga.Effect
  35. .put(callEffect, actionCreator: AppAction.updateITunesResults)
  36. }
  37. }
Add Comment
Please, Sign In to add comment