From 81299f543028ce48e48eb44d0ea37b934bbe725f Mon Sep 17 00:00:00 2001 From: YCM Jason Date: Sun, 21 Jul 2024 09:25:00 +0100 Subject: [PATCH] handle parent correctly in doc and collection Previously, `doc()` and `collection()` assumed `parent` to be a Collection and Document respectively. But I belive this is not the indended behaviour as we provided the overload for them to take in `Collection | Document`. See [here](https://github.com/invertase/react-native-firebase/blob/ad40ea2eb828a59451a619059bb4bef96277e23f/packages/firestore/lib/modular/index.d.ts#L213-L217). This commit adds support to this. --- packages/firestore/lib/modular/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/firestore/lib/modular/index.js b/packages/firestore/lib/modular/index.js index d6e8d52921..ecad9b74cf 100644 --- a/packages/firestore/lib/modular/index.js +++ b/packages/firestore/lib/modular/index.js @@ -35,6 +35,11 @@ export function doc(parent, path, ...pathSegments) { if (pathSegments && pathSegments.length) { path = path + '/' + pathSegments.map(e => e.replace(/^\/|\/$/g, '')).join('/'); } + + if ('collection' in parent) { + const [firstSegment, ...restSegments] = path.split('/'); + return parent.collection(firstSegment).doc(restSegments.join('/')); + } return parent.doc(path); } @@ -50,6 +55,11 @@ export function collection(parent, path, ...pathSegments) { path = path + '/' + pathSegments.map(e => e.replace(/^\/|\/$/g, '')).join('/'); } + if ('doc' in parent) { + const [firstSegment, ...restSegments] = path.split('/'); + return parent.doc(firstSegment).collection(restSegments.join('/')); + } + return parent.collection(path); }