ネイティブアプリでもFluxしたい

 ネイティブアプリでもFluxしたい

3fe447a7f9238108e6c50e97ac12717a?s=128

Kenichi Yonekawa

April 08, 2016
Tweet

Transcript

  1. @yonekawa ωΠςΟϒΞϓϦͰ΋ 'MVY͍ͨ͠

  2. ͸ʔ͍ϑϩϯτΤϯυͷ ษڧձͰ4XJGUͷ࿩͢ΔΑʔ

  3. ࡢࠓͷiOSΞϓϦ • RxSwiftʢϦΞΫςΟϒϓϩάϥϛϯάʣ͕ྲྀߦͷஹ͠ • MVVMΞʔΩςΫνϟ͕ຊ֨తʹྲྀߦ͖ͬͯͯΔ • ViewModelͰAPIୟ͍ͯViewʹྲྀ͠ࠐΉ • RxSwift͸UIόΠϯσΟϯά༻ͷ࢓૊Έ͕ॆ࣮

  4. freeeͷiOSΞϓϦ • MVVMΛॳظ͔Βಋೖ͠ɺViewModelʹΑͬͯViewͷঢ়ଶ ͱϏδωεϩδοΫΛ؅ཧ͍ͯ͠Δ • ϦΞΫςΟϒϓϩάϥϛϯάʹ͸ReactiveCocoaΛ࢖͍ͬͯ Δ • ෳࡶͳೖྗϑΥʔϜɺػೳͷଟ͞ͱͦΕΒͷؔ࿈ͷଟ͞

  5. ՝୊ײ • ن໛͕େ͖͘ͳΔʹͭΕͯUIΠϕϯτɺγεςϜΠϕϯτʹ ΑΔڍಈΛίϯτϩʔϧͰ͖ͳ͘ͳ͖ͬͯͨ • ViewModelͱͷ૒ํ޲όΠϯσΟϯάͱͦΕΒͷґଘؔ܎ ͷ༧ଌͷͮ͠Β͞ • ঢ়ଶͷ؅ཧͱϞσϧͷૢ࡞ͱAPIૢ࡞͕ີ݁߹

  6. Ͳ͜ͰԿ͕ى͖ͯΔ͔Α͘ Θ͔ΒΜ

  7. ୭͔ॿ͚ͯ͘Ε

  8. None
  9. ͓ͬʁ

  10. Ǒ2way-bindingͰ͸ɺViewModelͰViewͷ ஋΋Modelͷ஋΋؅ཧ͠ͳ͍ͱ͍͚ͳ͍ͱ ͜Ζ͕ͭΒ͞ͷݪҼʹͳ͍ͬͯΔɻ ǒ

  11. Θ͔Δɻ

  12. Ǒ͡Ό͋ͦ΋ͦ΋ViewΛඳը͢Δͱ͖ʹɺ Modelͷঢ়ଶ͔Βશ෦࠶ඳը͢Ε͹͍͍Μ ͡Όͳ͍ʁ ͦͨ͠ΒModelͷ஋Λ؅ཧ͢Δ͚ͩͰྑ͘ ͳͬͯɺViewͷ஋͸ߟ͑ͳͯ͘Α͘ͳΔΜ ͡Όͳ͍ʁ ǒ

  13. Ǒ͜ΕʹϐλϦͱ͸·Δͷ͕Fluxͱ͍͏֓೦ Ͱɺ͜Ε͸ViewͷதͰͷ஋ͷมߋΛͦͷ· ·View಺ͰॲཧΛͤͣɺผͷ૚ʹྲྀ͠ࠐΈ ·͢ɻ ǒ

  14. ͳΔ΄Ͳʁ

  15. SwiftFlux͍ͬͯ͏ϥΠϒϥϦΛ࡞ͬͨΑ • https://github.com/yonekawa/SwiftFlux • DispatcherͱͦΕʹඥͮ͘Action/Storeͷந৅Խ • ReduceStoreͱ͔Flux Utils΋Ұ෦࣮૷ͯ͠Δ • ϓϩτίϧࢦ޲ͰSwiftΒ͠͞Λҙࣝ

  16. ࣮ઓ౤ೖ΋ͯ͠ΔΑ https://itunes.apple.com/jp/app/id1037197002

  17. ୯ํ޲ϑϩʔ with ܕ੍໿ TUSVDU$SFBUF5PEP"DUJPO\ UZQFBMJBT1BZMPBE5PEP GVODJOWPLF EJTQBUDIFS%JTQBUDIFS \ MFUUPEP5PEP UJUMF/FX5P%P

     EJTQBUDIFSEJTQBUDI TFMG SFTVMU3FTVMU WBMVFUPEP  ^ ^ DMBTT5PEP4UPSF4UPSF#BTF\ QSJWBUF TFU WBSUPEP5PEP  JOJU \ SFHJTUFS $SFBUF5PEPTFMG \ SFTVMU JO TXJUDISFTVMU\ DBTF4VDDFTT MFUWBMVF  UPEPWBMVF FNJU$IBOHF  EFGBVMU CSFBL ^ ^ ^ ^
  18. ΞϓϦͷ։ൃํ਑ • جຊతʹViewControllerͱ1:1ͰStoreΛ࡞Γঢ়ଶΛ؅ཧ͢Δ • ͦΕͱผͰΞϓϦέʔγϣϯશମͷঢ়ଶʢೝূ͍ͯ͠Δͱ͔ʣ Λ؅ཧ͢ΔStoreΛ࡞Δ • APIϦΫΤετ͸ActionͰߦ͍݁ՌΛActionͷPayloadͱͯ͠ ѻ͏ •

    Realm(DB)΁ͷอଘ͸ΞϓϦέʔγϣϯͷঢ়ଶมԽͱΈͳ͠ StoreͰߦ͏
  19. Viewͷߋ৽͸Ͳ͏͢Δʁ • Swiftͷੈքʹ͸React͕ଘࡏ͠ͳ͍ɻͦΕͬΆ͍΋ͷ͸͍͘ ͔ͭ͋Δ͕ɺStoryboradͳͲϓϥοτϑΥʔϜ͕ఏڙ͢Δ ΋ͷ͔Β֎ΕΔͷ͸ϦεΫ͕ߴ͍ • ͋Δఔ౓͸UIKit͕ޮ཰Α͘࠶ඳըͯ͘͠ΕΔ͕ɺ UITableViewͳͲΛ͏·ࠩ͘෼ߋ৽͢Δ࢓૊Έ͕΄͍͠ • ࠓ͸ࣗ෼Ͱஸೡʹࠩ෼ߋ৽Λߦ͏ํ਑

  20. Τϥʔॲཧ • ActionͷPayloadͰErrorΦϒδΣΫτΛStoreʹ౉͠ɺStore ͕ঢ়ଶͱͯ͠อ࣋ • Τϥʔ΋ঢ়ଶΛม͑ΔActionͱͯ͠ѻ͏΂͖͔ • ͍·ͷSwiftFlux͸Swift2ͷthrowsΛ͏·͘࢖͍͑ͯͳ͍

  21. Ξχϝʔγϣϯ • ۪௚ʹ΍ΔͱFluxͷϑϩʔ͕େྔʹճΔ • Ξχϝʔγϣϯͷεςʔλεʢ։࢝ɺऴྃʣΛঢ়ଶͱͯ͠ѻ ͏΂͖͔ • JSͷํʑ͸Ͳ͏ઃܭͯ͠ΔΜͰ͔͢Ͷʁ

  22. ଞʹ͜͏͍͏ϥΠϒϥϦ͸ ແ͍ͷʁ

  23. ReSwift • https://github.com/ReSwift/ReSwift • Swift൛Reduxɻ࠷ۙ஫໨͞Ε͖ͯͯΔɻ • SwiftFluxͰ͸StoreGroupΛ࡞ͬͯࣅͨΑ͏ͳ͜ͱΛ΍Ζ͏ ͱͯ͠Δ͚Ͳ͜Ε͔Β

  24. ࢀߟϦϯΫ SwiftFluxͰෳࡶͳঢ়ଶͷมԽΛ༧ଌՄೳʹ͢ΔiOSΞϓϦ։ൃ http://qiita.com/yonekawa/items/c8a53d534084850963a3

  25. ωΠςΟϒΞϓϦͷ ϑϩϯτΤϯυ΋େม΍Ͱɻ