Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fluxで複雑な状態の変化を予測可能にするiOSアプリ開発

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 Fluxで複雑な状態の変化を予測可能にするiOSアプリ開発

Avatar for Kenichi Yonekawa

Kenichi Yonekawa

April 13, 2016
Tweet

More Decks by Kenichi Yonekawa

Other Decks in Programming

Transcript

  1. Store ViewController Store ViewController ߏ੒ Dispatcher Action Action Store Store

    (Global) Store ViewController ActionCreator Action Action Application
  2. struct FetchTodo: Action { typealias Payload = [Todo] func invoke(dispatcher:

    Dispatcher) { Session.sendRequest(FetchTodoRequest()) { result in switch result { case .Success(let todos): dispatcher.dispatch(self, result: Result(value: todos)) case .Failure(let error): dispatcher.dispatch(self, result: Result(error: error)) } } } } Action
  3. class TodoStore: StoreBase { private(set) var todos: [Todo] private(set) var

    error: Error? func init() { register(FetchTodo.self) { (result) in switch result { case .Success(let todos): error = nil self.todos = payload emitChange() case .Failure(let error): self.error = error emitChange() } } } } Store
  4. class ViewController: UITableViewController { let store = TodoStore() func viewDidLoad()

    { super.viewDidLoad() store.subscribe { () in tableView.reloadData() } ActionCreator.invoke(FetchAction()) } } ViewController
  5. Redux or Flux? • جຊతʹ͸ReduxͷSingle State Tree͸ΑΓྑ͍ঢ়ଶ؅ཧͷ ࢓૊ΈΛఏڙͯ͘͠ΕΔͷͰΑ͍ • Redux͸Single

    State TreeΛલఏʹσβΠϯ͞Ε͍ͯΔͷ ͰɺΞϓϦέʔγϣϯશମΛͦΕલఏʹ࡞Βͳ͍ͱ͍͚ͳ͍ • Flux͸੍໿͕؇͍ͷͰɺෳࡶͳUIΛ෦෼తʹஔ͖׵͑ΔͳͲ طଘͷΞϓϦʹ΋ೖΕ΍͍͢