-
-
Notifications
You must be signed in to change notification settings - Fork 970
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
Mutation: Access mutated data #3937
Comments
Isn't that already the case? |
If I understand it correctly, the E.g. a Currently: SuccessMutationState(List<Todo> value) Proposed: SuccessMutationState(Todo value) |
How would Riverpod know what that is? |
Can you elaborate? Benefits:
ref.listen(todoListProvider.addTodo, (_, addTodo) {
switch(addTodo.state) {
SuccessMutationState(value: Todo todo) => showSnackbar(content=Text("Added ${value.name}")),
_=> null,
}
}); |
How would Riverpod know what that |
Hopefully I get your question correctly. 😀 @riverpod
class Todos {
Future<List<Todo>> build () asnyc => ...;
@mutation
Future<Todo> addTodo(Todo value) async {
final newTodo = client.addTodo(value);
return newTodo;
}
} |
But then Riverpod won't know how to update the state, as At minimum we'd need: addTodo(todo) {
final newTodo = client.addTodo(value);
state = [...state, todo];
return newTodo;
} |
This looks good to me. I don't see a way to not explicitly update the state. Note: Should an error in a |
That'd require changing how mutations works.
No, I don't think that makes sense |
Agreed. I also do not think that this should be the default, but it might be something that some users want. This could be a annotation flag. |
We can revisit that later. That's not something I'd ship in the initial release |
Description
Currently, riverpod gives access to the mutated state using
ref.listen()
/ref.watch()
.Suggestion
Riverpod should enable us to access the mutated data directly, e.g. the data of a
addTodo
mutation would be the newly added todo.If the mutation is in a success state, the data is available via the data property.
The text was updated successfully, but these errors were encountered: