Mutations
Defining a mutation
class UpdateMessageMutation extends Mutation {
@override
String get name => 'changeMessage'; // if you don't override it will be the name of class: 'UpdateMessageMutation'
@override
void call(Map<String, dynamic> state, payload) {
state['message'] = payload;
}
}
All mutations should be sync, if you need to perform async operations you must use an action
Registering the mutation on Store
class MyStore extends Store {
MyStore() : super(
Module(
state: {
'message': 'A message',
},
mutations: [
UpdateMessageMutation(),
],
),
);
}
Commiting a change
store.commit('/changeMessage', 'New message');
Last updated
Was this helpful?