Skip to content

Commit

Permalink
fix: Fixed a bug that prevented data from updating properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Feb 1, 2023
1 parent b143408 commit 9c008f9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
18 changes: 14 additions & 4 deletions packages/katana_model/lib/src/model_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ class ModelAdapterDocumentQuery {
bool operator ==(Object other) => hashCode == other.hashCode;

@override
int get hashCode => query.hashCode ^ origin.hashCode;
int get hashCode {
if (origin != null) {
return origin.hashCode;
}
return query.hashCode;
}
}

/// Query class to be passed when executing each function of [ModelAdapter].
Expand Down Expand Up @@ -474,9 +479,9 @@ class ModelAdapterCollectionQuery {
/// リクエストを送る際のメソッド。
final String? method;

/// Page number to be read. If [ModelQuery.limit] is set, additional reading is performed according to this page number.
/// Page number to be read. If [ModelQueryFilterType.limit] is set, additional reading is performed according to this page number.
///
/// 読込のページ番号。[ModelQuery.limit]が設定されている場合、こちらのページ番号に応じて追加読込を行います。
/// 読込のページ番号。[ModelQueryFilterType.limit]が設定されている場合、こちらのページ番号に応じて追加読込を行います。
final int page;

/// A callback that is notified when there is a change in the corresponding collection.
Expand Down Expand Up @@ -520,5 +525,10 @@ class ModelAdapterCollectionQuery {
bool operator ==(Object other) => hashCode == other.hashCode;

@override
int get hashCode => query.hashCode ^ origin.hashCode;
int get hashCode {
if (origin != null) {
return origin.hashCode;
}
return query.hashCode;
}
}
45 changes: 25 additions & 20 deletions packages/katana_model/lib/src/model_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1161,25 +1161,30 @@ class ModelQuery {
bool operator ==(Object other) => hashCode == other.hashCode;

@override
int get hashCode =>
filters.fold<int>(
path.trimQuery().trimString("/").hashCode,
(p, e) => p ^ e.hashCode,
) ^
key.hashCode ^
isEqualTo.hashCode ^
isNotEqualTo.hashCode ^
isLessThanOrEqualTo.hashCode ^
isGreaterThanOrEqualTo.hashCode ^
arrayContains.hashCode ^
arrayContainsAny.hashCode ^
whereIn.hashCode ^
whereNotIn.hashCode ^
geoHash.hashCode ^
order.hashCode ^
limit.hashCode ^
orderBy.hashCode ^
searchText.hashCode;
int get hashCode {
final p = path.trimQuery().trimString("/").hashCode;
if (filters.isNotEmpty) {
return filters.sortTo((a, b) => a.hashCode - b.hashCode).fold<int>(
p,
(p, e) => p ^ e.hashCode,
);
}
return p ^
key.hashCode ^
isEqualTo.hashCode ^
isNotEqualTo.hashCode ^
isLessThanOrEqualTo.hashCode ^
isGreaterThanOrEqualTo.hashCode ^
arrayContains.hashCode ^
arrayContainsAny.hashCode ^
whereIn.hashCode ^
whereNotIn.hashCode ^
geoHash.hashCode ^
order.hashCode ^
limit.hashCode ^
orderBy.hashCode ^
searchText.hashCode;
}

@protected
String _limit([String path = ""]) {
Expand Down Expand Up @@ -1734,7 +1739,7 @@ class ModelQueryFilter {
@override
int get hashCode {
final val = value;
if (val is List) {
if (val is List && val.isNotEmpty) {
return val
.sortTo()
.fold(type.hashCode ^ key.hashCode, (p, e) => p ^ e.hashCode);
Expand Down
28 changes: 15 additions & 13 deletions packages/katana_model/lib/src/no_sql_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,19 +733,21 @@ class NoSqlDatabase {
final oldIndex = entries.indexWhere(
(e) => e.key.trimQuery().trimString("/") == documentId,
);
_collectionEntries[element] = entries..removeAt(oldIndex);
element.callback?.call(
ModelUpdateNotification(
path: documentPath,
id: documentId,
status: ModelUpdateNotificationStatus.removed,
value: const {},
origin: query.origin,
oldIndex: oldIndex < 0 ? null : oldIndex,
newIndex: null,
listen: query.listen,
),
);
if (oldIndex >= 0) {
_collectionEntries[element] = entries..removeAt(oldIndex);
element.callback?.call(
ModelUpdateNotification(
path: documentPath,
id: documentId,
status: ModelUpdateNotificationStatus.removed,
value: const {},
origin: query.origin,
oldIndex: oldIndex < 0 ? null : oldIndex,
newIndex: null,
listen: query.listen,
),
);
}
}
break;
case ModelUpdateNotificationStatus.removed:
Expand Down
9 changes: 5 additions & 4 deletions packages/katana_model_firestore/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ packages:
katana_model:
dependency: "direct main"
description:
path: "../katana_model"
relative: true
source: path
version: "1.5.0"
name: katana_model
sha256: abbd1feb134ce2b33cfcfb3e2536516d1446cd4123d36f329400cc7d1caf59bc
url: "https://pub.dev"
source: hosted
version: "1.5.1"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit 9c008f9

Please sign in to comment.