-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Observer.optimized #952
Observer.optimized #952
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #952 +/- ##
=======================================
Coverage 98.99% 98.99%
=======================================
Files 57 57
Lines 1992 1998 +6
=======================================
+ Hits 1972 1978 +6
Misses 20 20
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
50c401d
to
fc46ddc
Compare
flutter_mobx/lib/src/observer.dart
Outdated
final WidgetBuilder builder; | ||
/// Observer which excludes the child branch | ||
// ignore: prefer_const_constructors_in_immutables | ||
Observer.optimized({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call this withChild
to make the intent clear. The idea is to only build parts that are actually changing and keeping rest of the tree intact. I think you would also need a withChildren
variant as well which could be a Map<String, Widget>
?. This variant will help in plugging in parts of the tree which are not changing. This is useful when you have more than one child.
@pavanpodila done. I renamed I applied the same technique which was used in AnimatedBuilder, and |
@all-contributors add @subzero911 for code |
@subzero911 already contributed before to code |
I already did a PR #909 but I accidentally deleted the forked repo.
So I made it again and a little bit better.
Mostly you try to make Observer as small as possible. But sometimes you'll want to exclude the widget subtree from re-render and improve the performance.
Real world examples:
ListView
withshrinkWrap: true
).You want to change the color by Observable, but don't want to rebuild the whole ListView.
I introduce the new
Observer.optimized
which allows you to exclude thechild
branch.Usage:
Solves #551
@amondnet @fzyzcjy
Pull Request Checklist
pubspec.yaml
is updated.major
/minor
/patch
/patch-count
, depending on the complexity of changemelos run set_version
command from the root directory