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

MobX - Making state management simple

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

MobX - Making state management simple

This sessions demostrates basic usage of MobX in flutter application.

Avatar for Devarsh Ranpara

Devarsh Ranpara

February 19, 2021

More Decks by Devarsh Ranpara

Other Decks in Programming

Transcript

  1. Why not setState? • No extra config required • Easy

    to understand • No boilerplate code
  2. Say hello to MobX 🙋 • Works on reactive programming

    concept • Easy to understand • Less boilerplate code (Thanks to build runner)
  3. Observable • Tracks a single value (primitive or complex) •

    Fires a notification when it changes value so that all connected reactions will re-execute.
  4. Action • A function that mutates the Observable • Changes

    to the observables are only notified at the end of the action Do not mutate observables outside an action.
  5. Reaction • Triggers the reactivity in the system • A

    reaction implicitly tracks all the observables which are being used and then re-executes its logic whenever the depending observables change • No explicit subscription or wiring needed
  6. MobX Observer • Re-renders observer when reaction is triggered •

    Builder function tracks observable in immediate execution context • Do not use nested function inside Observer builder
  7. @computed • Creates value as computed. • It can track

    multiple value to avoid conditional code in business logic
  8. Generate .g file • Create class • Add .g file

    • Create abstract class • Fire build runner commands