update method
Updates _data inside the repository.
If the creation is sucessful, will return true. Otherwise, false.
Note: userId is automatically applied to existingData.
Implementation
Future<bool> update(T existingData) async {
if (!_data.any((element) => element.id == existingData.id) || !isInstanceValid(existingData)) {
AppEventsDispatcher().publish(OperationFailedEvent(OperationType.update, service.repositoryId, existingData));
return false;
}
if (assignUserIdOnUpdate) {
existingData = existingData.copyWith(userId: userId) as T;
}
_data.replace(existingData);
await service.update(existingData);
notifyListeners();
AppEventsDispatcher().publish(DataUpdatedEvent(service.repositoryId, existingData));
return true;
}