CollectionBase<TModel extends DocumentBase> constructor

CollectionBase<TModel extends DocumentBase>(
  1. CollectionModelQuery _modelQuery, [
  2. List<TModel>? value
])

Define a collection model that includes DocumentBase as an element.

Any changes made locally in the app will be notified and related objects will reflect the changes.

When changes are reflected, notifyListeners will notify all listeners of the changes.

Define CollectionBase.create to describe the process of creating a new document.

By defining modelQuery, you can specify settings for loading, such as collection paths and conditions.

The collection implements List, but changing an element is Unmodifiable and will result in an error.

Execute DocumentBase.save for each document to change elements, and DocumentBase.delete for each document to delete them.

To add elements, run CollectionBase.create to create a new document, then save it with DocumentBase.save.

DocumentBaseを要素に含めたコレクションモデルを定義します。

アプリのローカル内での変更はすべて通知され関連のあるオブジェクトは変更内容が反映されます。

変更内容が反映された場合notifyListenersによって変更内容がすべてのリスナーに通知されます。

CollectionBase.createを定義することで新規にドキュメントを作成する処理を記述します。

modelQueryを定義することで、コレクションのパスや条件など読み込みを行うための設定を指定できます。

コレクションはListを実装していますが、要素の変更はUnmodifiableとなりエラーになります。

要素を変更する場合は各ドキュメントのDocumentBase.saveを実行し、削除する場合は各ドキュメントのDocumentBase.deleteを実行してください。

要素を追加する場合はCollectionBase.createを実行し新しいドキュメントを作成したあと、DocumentBase.saveで保存してください。

Implementation

CollectionBase(
  this._modelQuery, [
  List<TModel>? value,
])  : __value = value ?? [],
      assert(
        !(_modelQuery.path.trimQuery().trimString("/").splitLength() <= 0 ||
            _modelQuery.path.trimQuery().trimString("/").splitLength() % 2 !=
                1),
        "The query path hierarchy must be an odd number: ${_modelQuery.path}",
      );