Skip to content

Commit

Permalink
fix(firestore, web): fix a casting error with the update method (#10458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone authored Feb 16, 2023
1 parent 7a2a7e5 commit 696a6ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,15 @@ class DocumentReference
return handleThenable(jsObjectSet);
}

Future<void> update(Map<FieldPath, dynamic> data) =>
handleThenable(firestore_interop.updateDoc(jsObject, jsify(data)));
Future<void> update(Map<firestore_interop.FieldPath, dynamic> data) {
final alternatingFieldValues =
data.keys.map((e) => [e, data[e]]).expand((e) => e).toList();

return handleThenable(callMethod(firestore_interop.updateDoc, 'apply', [
null,
[jsObject, ...alternatingFieldValues]
]));
}
}

class Query<T extends firestore_interop.QueryJsImpl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ external PromiseJsImpl<void> terminate(FirestoreJsImpl firestore);
@JS()
external PromiseJsImpl<void> updateDoc(
DocumentReferenceJsImpl reference,
dynamic data,
);
/*string | FieldPath*/ dynamic field,
dynamic value, [
dynamic moreFieldsAndValues,
]);

@JS()
external PromiseJsImpl<void> waitForPendingWrites(FirestoreJsImpl firestore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class EncodeUtility {
return output;
}

static Map<FieldPath, dynamic>? encodeMapDataFieldPath(
static Map<firestore_interop.FieldPath, dynamic>? encodeMapDataFieldPath(
Map<Object, dynamic>? data) {
if (data == null) {
return null;
}
Map<FieldPath, dynamic> output = <FieldPath, dynamic>{};
final output = <firestore_interop.FieldPath, dynamic>{};
data.forEach((key, value) {
output[valueEncode(key)] = valueEncode(value);
});
Expand Down

0 comments on commit 696a6ba

Please sign in to comment.