ややcomplexなBLoCへの対応

 ややcomplexなBLoCへの対応

"Flutter Meetup Tokyo #7"でのLT資料です。
https://flutter-jp.connpass.com/event/115645/

4c6ec167a614173c5b31aaf4d1defa19?s=128

Hiroki Matsue

January 30, 2019
Tweet

Transcript

  1. ΍΍complexͳBLoC΁ͷରԠ Hiroki Matsue Jan 30th, 2019 Flutter Meetup Tokyo #7

  2. Hiroki Matsue (@macs_6)

  3. IIJmio޲͚ʮΈ͓εΠονʯ (Flutter੡)

  4. analysis͸࢝Ίʹઃఆ͠Α͏ omit_local_variable_types༗ޮʹ͠·͠ΐ͏ https://www.dartlang.org/guides/language/effective-dart/design#avoid-type-annotating- initialized-local-variables

  5. લճ͸Dart೉ಡԽͷ࿩

  6. ࠓճ͸BLoCͷ࿩

  7. BLoCͷ͓͞Β͍

  8. Business Logic Componentsύλʔϯ

  9. Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

  10. Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

  11. Google I/O '18: https://www.youtube.com/watch? v=RS36gBEp8OI

  12. ϓϩτλΠϓҎ߱ͷϑΣʔζ͸ɺBLoC ΍Reduxಋೖ͓ͯ͘͠ͱ҆৺

  13. ը໘1ͭʹBLoC1ͭͷγϯϓϧͳ ঢ়ଶ؅ཧͷ৔߹

  14. buttonͦΕͧΕʹLoading΍ErrorΛ දݱ͍ͨ͠ (ΞΠςϜҰཡ͔Β1ͭΛ͓ؾʹೖΓɺΧʔυʹೖΕΔɺetc)

  15. ͜Μͳ࣌

  16. αϯϓϧ࣮૷Ͱͷ૝ఆσʔλߏ଄ - ܖ໿1 - sim1 - sim2 - ... -

    ܖ໿2 - ... - ...
  17. ·ͣܖ໿ͱSIM2ͭͷBLoCΛܨ͙ You should avoid having one BLoC as a parameter

    of another BLoC. Instead, plug only the required outputs to the applicable inputs. This helps avoid tight coupling. https://medium.com/flutter-io/build-reactive-mobile-apps-in-flutter-companion- article-13950959e381 _bloc = SimBloc(widget.sim); // ܖ໿BLoCͷstreamΛSIMBLoC͕listen _subscription = widget.simsStream.listen(_bloc.sims.add);
  18. ܨ͍ͩΒ2ͭ໨ͷBLoC಺ʹࢦఆͨ͠ SIMΛॲཧ͢ΔϩδοΫΛॻ͘

  19. class SimBloc { SimBloc(Sim sim) { _simController.stream .map((list) => list.firstWhere((s)

    => s == sim, orElse: () => null)) .listen((sim) { if (sim == null) { log(errorMessage); // print log and send error to Sentry return; } _simSubject.add(SimState( switchingStatus: SimSwitchingStatus.fulfilled, isEnabled: sim.isEnabled, usage: sim.inMonthUsage(), )); ...
  20. ࢀߟ: filiph/state_experiments@github (ಛʹbloc_complexपΓ)

  21. BLoCಋೖͯ͠ྑ͔ͬͨ͜ͱ • ϘλϯͷΑ͏ͳ୯ҐͰͷঢ়ଶΛ؅ཧ͠΍͘͢ͳͬͨ • ςετ͕ॻ͖΍͘͢ͳͬͨ

  22. Έ͓εΠονɺੋඇ͝ར༻͍ͩ͘͞

  23. Thanks