-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
riverpod_graph: don't crash on: 1) provider is a method of instance of another provider 2) recursive watch calls, like: ref.watch(ref.watch(provider)) #2870
Conversation
…here provider is a method of instance of another provider state, i.e.: final worker = ref.watch(currentWorker); final clients = ref.watch(worker.clientsOf) there: class Worker{ Provider get clients => clientsOfWorker(this); // other code.... }
ref.watch(ref.watch(provider))
We could fail more gracefully, but that's not supposed to be supported. Folks shouldn't do this. Providers should exclusively be top-level final variables. |
First and foremost, this would need testing :) But given my previous comment, I'm not sure I reasonably want to support this. At best we should have a nice error message I'd say. In any case, your work is bound to be removed soon enough. If we want to do such a thing, I'd suggest implementing this in riverpod_analyzer_utils first. Then refactoring riverpod_graph to use it. |
first, sorry for typo: Not sure why it's not supported. There are cases where I need to access a specific family member of
actually, is there a discussion on this topic? (I understand that it may be more challenging to implement, fine if it is the case, but it seems usable.) and for use cases: final worker = ref.watch(currentWorker);
final client = ref.watch(worker.clientsOf).first;
final services = ref.watch(client.servicesOf);
final worker = ref.watch(currentWorker);
final client = ref.watch(clients(worker)).first;
final services = ref.watch(services(client)); An alternative proposition is as follows(but no auto-completion here(( ): final worker = ref.watch(currentWorker);
final client = ref.watch(clients.of(worker)).first;
final service = ref.watch(services.of(client)).first;
final proofs = ref.watch(proofs.of(service)); |
Anyway, thank for good work and good package)) |
Sorry, did you mean: i should also provide tests? I just used riverpod_graph on my project, and these are the patches that made it work. Sorry for third patch - i promise, next time i will look into (btw, |
That's much better. I agree with this one |
Outside of possible memory leak, it's straight up not possible when considering codegen – which is the new recommended syntax |
Yes we need automated tests, to avoid regressions |
ok, next patch will be with tests btw, the third patch was a fix for this use case: final serviceProofAtDate =
Provider.family<(List<Proof>, ProofList), ClientService>(
(ref, service) {
final proofList = proofListProvider(
contractId: service.contractId,
// another 6 parameters here...
);
return ref.watch(proofList); // local variable proofList
},
); |
Folks shouldn't do this either. Sure, the graph shouldn't crash. But it would at least warn All usages of ref.read/watch/listen must be statically analysable. This is important for certain features which rely on static analysis |
I'll close this as riverpod_graph needs an effective rewrite and initial release. This problem should fix itself by switching to riverpod_analyzer_utils. |
ConsumerWidgetVisitor: store map of local variables, to solve cases there provider is a method of instance of another provider state, i.e.:
ConsumerWidgetVisitor: allow recursive watch, like: