one<T> method

  1. @override
Future<void> one<T>(
  1. T object, {
  2. String? subcollection,
})
override

Updates a document in Localstore with the given object.

Implementation

@override
Future<void> one<T>(T object, { String? subcollection }) {
  final serializer = LS.serializers[object.runtimeType];
  final String? className = LS.classNames[object.runtimeType];

  if (serializer == null || className == null) {
    throw UnsupportedError('No serializer/class name found for type: $className. Consider re-generating Firestorm data classes.');
  }
  final map = serializer(object);
  if (map["id"].isEmpty) {
    throw NullIDException(map);
  }
  DocumentRef ref = LS.instance.collection(className).doc(map["id"]);
  if (subcollection != null) {
    ref = LS.instance.collection(className).doc(subcollection).collection(subcollection).doc(map["id"]);
  }
  return ref.set(map);
}