streamAsModels<MT extends StorageModel> method

Stream<List<MT>> streamAsModels<MT extends StorageModel>([
  1. bool where(
    1. MT
    )?,
  2. Duration delayCheck = const Duration(milliseconds: 50)
])

Implementation

Stream<List<MT>> streamAsModels<MT extends StorageModel>([
  bool Function(MT)? where,
  Duration delayCheck = const Duration(milliseconds: 50),
]) => stream(delayCheck: delayCheck).asyncExpand<List<MT>>((data) async* {
  if (data != null) {
    if (data is Map) {
      List<MT> items = data.toListModel<MT>();
      if (where != null) {
        items = items.where(where).toList();
      }
      yield items;
    } else if (data is List) {
      List<MT> items = data.toModels<MT>();
      if (where != null) {
        items = items.where(where).toList();
      }
      yield items;
    }
  }
});