Comments (2)
Hey Luke, it would be really easy to add such a widget, but it sort of defeats the purpose of the library, IMO, so I'm quite hesitant about adding it to the lib. Let me explain.
- The
watch
function from the builder parameter would have to both accept and returndynamic
, which is going to be annoying to work with. Extensions on observable types donβt have such a problem and allow for defining the whole different method signatures based on the receiver type. This gets even more important with the v2 of this package, as β.watch()β will now returnAsyncSnapshot<T>
forStream<T>
/Future<T>
,T
forValueListenable<T>
and theListenable
instance itself for anyListenable
. - I could introduce something like
WatchBuilder((context) => β¦)
, which would just do this:
class WatchBuilder extends StatelessWidget {
const WatchBuilder({
super.key,
required this.builder,
});
final WidgetBuilder builder;
Widget build(BuildContext context) {
context.unwatch();
return builder(context);
}
}
, but, to me, it looks worse in terms of DX compared to just adding the context.unwatch()
by hand where/if needed. Especially since in v2 this call is even cheaper and can be made anywhere inside the build
method body, even multiple times - with the same result.
3. Not using the context.unwatch()
at_all should_not break anything in terms of app's logic/UI:
- Observable subscription WILL be canceled when the Widget is unmounted.
- Observable subscription WILL be canceled immediately when the corresponding
.watch()
call is conditionally replaced with another.watch()
call within thebuild
method. - The only possible manifestation of the mentioned Flutter's limitation is some potential extra rebuilds if suddenly ALL of the
.watch()
/context.unwatch()
calls have disappeared from thebuild
method's body.
- I intended to replicate the InheritedWidget subscription (
Something.of(context)
) behavior for every observable type out there + make the package stupidly simple to learn and use. This proposal doesn't align with the mentioned vision, IMO. - I'm almost ready to release another package, which would provide an easier-to-use&read alternative to the InheritedWidget, which will be integrated with
context_watch
in such a way that everytime you access this "InheritedWidget's alternative" within thebuild
method -context.unwatch()
will be triggered automatically, making the potential extra rebuilds even less possible, without any additional work from your side. So, if your use-case involves any parent tree lookup for something, you might want to take a look at that new package. I'll let you know when it's released if you're interested. context_watch
v2 will provide a.watchValue(context, (observable) => observable.property)
extension to make a widget rebuild only when the specific property value changes. This might help with getting rid of some conditional.watch()
calls.
from context_plus.
context_watch 2.0, along with context_ref and context_plus are out now. Check them out to enjoy even less likely unwanted conditional watch()
related rebuilds.
from context_plus.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from context_plus.