Skip to content

Commit

Permalink
fix: Fixed a bug that occurred when changing the value when searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Feb 3, 2023
1 parent 11543b3 commit c4c01bb
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/katana_model/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.5.5"
version: "1.5.6"
lints:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions packages/katana_model/lib/src/collection_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ abstract class CollectionBase<TModel extends DocumentBase>
/// [update]の内容に応じて適切な処理を行ってください。
@protected
Future<void> handledOnUpdate(ModelUpdateNotification update) async {
if (update.query != modelQuery) {
return;
}
var notify = false;
switch (update.status) {
case ModelUpdateNotificationStatus.added:
Expand Down
3 changes: 3 additions & 0 deletions packages/katana_model/lib/src/document_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ abstract class DocumentBase<T> extends ChangeNotifier
/// [update]の内容に応じて適切な処理を行ってください。
@protected
Future<void> handledOnUpdate(ModelUpdateNotification update) async {
if (update.query != modelQuery) {
return;
}
final val = value;
final filtered = _filterOnLoad(update.value);
if (filtered.isEmpty) {
Expand Down
3 changes: 0 additions & 3 deletions packages/katana_model/lib/src/model_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,6 @@ class ModelAdapterCollectionQuery {

@override
int get hashCode {
if (origin != null) {
return origin.hashCode;
}
return query.hashCode;
}
}
6 changes: 3 additions & 3 deletions packages/katana_model/lib/src/model_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1753,11 +1753,11 @@ class ModelQueryFilter {
}
final splitBygram = target.toLowerCase().splitByBigram();
for (final text in splitBygram) {
if (source.get(text, false)) {
return true;
if (!source.get(text, false)) {
return false;
}
}
return false;
return true;
default:
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/katana_model/lib/src/model_update_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ModelUpdateNotification {
required this.status,
required this.value,
required this.listen,
required this.query,
this.origin,
this.oldIndex,
this.newIndex,
Expand Down Expand Up @@ -87,6 +88,11 @@ class ModelUpdateNotification {
/// クエリーを監視中の場合は`true`.
final bool listen;

/// [ModelQuery] to be updated.
///
/// アップデート対象の[ModelQuery]
final ModelQuery query;

@override
String toString() {
return "$runtimeType(path: $path, id: $id, status: $status, origin: $origin, value: $value, listen: $listen)";
Expand Down
10 changes: 8 additions & 2 deletions packages/katana_model/lib/src/no_sql_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class NoSqlDatabase {
.removeEmpty(),
)
.sublist(0, limitValue);
_collectionEntries[query] = entries;
_collectionEntries[query] = List.from(entries);
return Map<String, DynamicMap>.fromEntries(entries);
}

Expand Down Expand Up @@ -405,7 +405,7 @@ class NoSqlDatabase {
.removeEmpty(),
)
.sublist(0, limitValue);
_collectionEntries[query] = entries;
_collectionEntries[query] = List.from(entries);
await onSaved?.call(this);
return value;
}
Expand Down Expand Up @@ -685,6 +685,7 @@ class NoSqlDatabase {
value: Map.from(value),
origin: query.origin,
listen: query.listen,
query: element.query,
),
),
);
Expand Down Expand Up @@ -712,6 +713,7 @@ class NoSqlDatabase {
oldIndex: null,
newIndex: newIndex,
listen: query.listen,
query: element.query,
),
);
break;
Expand All @@ -736,6 +738,7 @@ class NoSqlDatabase {
oldIndex: null,
newIndex: newIndex,
listen: query.listen,
query: element.query,
),
);
} else {
Expand All @@ -757,6 +760,7 @@ class NoSqlDatabase {
oldIndex: oldIndex < 0 ? null : oldIndex,
newIndex: newIndex,
listen: query.listen,
query: element.query,
),
);
}
Expand All @@ -776,6 +780,7 @@ class NoSqlDatabase {
oldIndex: oldIndex < 0 ? null : oldIndex,
newIndex: null,
listen: query.listen,
query: element.query,
),
);
}
Expand All @@ -796,6 +801,7 @@ class NoSqlDatabase {
oldIndex: oldIndex < 0 ? null : oldIndex,
newIndex: null,
listen: query.listen,
query: element.query,
),
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class ListenableFirestoreModelAdapter extends ModelAdapter {
newIndex: doc.newIndex,
origin: query.origin,
listen: availableListen,
query: query.query,
),
);
}
Expand All @@ -162,6 +163,7 @@ class ListenableFirestoreModelAdapter extends ModelAdapter {
value: _convertFrom(doc.data()?.cast() ?? {}),
origin: query.origin,
listen: availableListen,
query: query.query,
),
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/katana_model_firestore/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ packages:
path: "../katana_model"
relative: true
source: path
version: "1.5.4"
version: "1.5.6"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit c4c01bb

Please sign in to comment.