mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.4k stars 310 forks source link

[Feature Request] make updated and subscriptions to atoms with identifier #805

Open AladdinYasser opened 2 years ago

AladdinYasser commented 2 years ago

if we have an Atom we want to subscribe to the atom in observers with an id reportObserved('1');, and then we need to make the updates also with ids reportChanged('1');, That's because we have multiple observers for the same Atom and we don't want to rebuild all the Observers in case of any update on the Atom, therefore specific Observers that should be rebuilded only based on the update id.

In the example below only the Observer number 1 should be rebuilded although that the two Observers are connected with the same Atom

Column(children: [
            Observer(
              builder: (context) {
                atom.reportObserved('1');

                return Text('data');
              },
            ),
            Observer(
              builder: (context) {
                atom.reportObserved('2');

                return Text('data');
              },
            ),
            ElevatedButton(
              onPressed: () {
                atom.reportChanged('1');
              },
              child: Text('make update'),
            ),
          ])