Skip to content

Commit

Permalink
fix: Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed May 14, 2024
1 parent ba56792 commit 13cc2f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
18 changes: 12 additions & 6 deletions packages/katana_model/lib/src/collection_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ abstract class CollectionBase<TModel extends DocumentBase>
}
final value = create(update.id.trimQuery().trimString("?"));
final val = value.value;
final filtered = value._filterOnLoad(update.value);
final filtered =
value.filterOnLoad(ModelFieldValue.fromMap(update.value));
if (filtered.isEmpty) {
value._value = null;
// 最初にいれないと要素が無いエラーがでる場合がある
Expand All @@ -537,19 +538,24 @@ abstract class CollectionBase<TModel extends DocumentBase>
_value.length < update.newIndex!) {
return;
}
final found = _value.removeAt(update.oldIndex!);
// 位置が変わっているのにデータが来た場合は無視
// 指定位置に違うデータが来た場合は無視
final found = _value[update.oldIndex!];
if (found.uid != update.id) {
return;
}
final val = found.value;
final filtered = found._filterOnLoad(update.value);
final filtered =
found.filterOnLoad(ModelFieldValue.fromMap(update.value));
if (filtered.isEmpty) {
found._value = null;
// 削除と挿入は同時に行わないと不具合が発生する
_value.removeAt(update.oldIndex!);
// 最初にいれないと要素が無いエラーがでる場合がある
_value.insert(update.newIndex!, found);
} else {
final fromMap = found._value = found.fromMap(filtered);
// 削除と挿入は同時に行わないと不具合が発生する
_value.removeAt(update.oldIndex!);
// 最初にいれないと要素が無いエラーがでる場合がある
_value.insert(update.newIndex!, found);
found._value = await found.filterOnDidLoad(fromMap);
Expand Down Expand Up @@ -608,8 +614,8 @@ abstract class CollectionBase<TModel extends DocumentBase>
continue;
}
final value = create(key);
final filtered = value._filterOnLoad(
Map<String, dynamic>.unmodifiable(tmp.value),
final filtered = value.filterOnLoad(
ModelFieldValue.fromMap(Map<String, dynamic>.unmodifiable(tmp.value)),
);
if (filtered.isEmpty) {
value._value = null;
Expand Down
9 changes: 2 additions & 7 deletions packages/katana_model/lib/src/document_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ abstract class DocumentBase<T> extends ChangeNotifier
if (!loaded) {
final res = await loadRequest();
if (res != null) {
final filtered = _filterOnLoad(res);
final filtered = filterOnLoad(ModelFieldValue.fromMap(res));
if (filtered.isEmpty) {
_value = null;
} else {
Expand Down Expand Up @@ -481,11 +481,6 @@ abstract class DocumentBase<T> extends ChangeNotifier
@mustCallSuper
DynamicMap filterOnLoad(DynamicMap rawData) => rawData;

// 内部処理を加えるために内部ではこちらを使用。
DynamicMap _filterOnLoad(DynamicMap rawData) {
return filterOnLoad(ModelFieldValue.fromMap(rawData));
}

/// Callback called after loading.
///
/// If [loaded] is `true`, it will not be executed.
Expand Down Expand Up @@ -544,7 +539,7 @@ abstract class DocumentBase<T> extends ChangeNotifier
return;
}
final val = value;
final filtered = _filterOnLoad(update.value);
final filtered = filterOnLoad(ModelFieldValue.fromMap(update.value));
if (filtered.isEmpty) {
_value = null;
} else {
Expand Down
4 changes: 3 additions & 1 deletion packages/katana_model/lib/src/model_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ class ModelTransactionDocument<T> {
FutureOr<T?> load() async {
final document = _document;
final res = await _ref._load(document);
document._value = document.fromMap(document._filterOnLoad(res));
document._value = document.fromMap(
document.filterOnLoad(ModelFieldValue.fromMap(res)),
);
return value;
}

Expand Down

0 comments on commit 13cc2f1

Please sign in to comment.