Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit c817dc6

Browse files
cleanup
1 parent 191d41c commit c817dc6

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed

src/firebase-common.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,7 @@ export const firebase: any = {
188188
};
189189

190190
export class DocumentSnapshot implements firestore.DocumentSnapshot {
191-
public id: string;
192-
public exists: boolean;
193-
public docSnapshot: firestore.DocumentSnapshot;
194-
195-
data(): firestore.DocumentData {
196-
return this.docSnapshot;
191+
constructor(public id: string, public exists: boolean, public data: () => firestore.DocumentData) {
197192
}
198193
}
199194

src/firebase.android.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { firebase, QuerySnapshot } from "./firebase-common";
1+
import { DocumentSnapshot, firebase, QuerySnapshot } from "./firebase-common";
22
import * as appModule from "tns-core-modules/application";
33
import { AndroidActivityResultEventData } from "tns-core-modules/application";
44
import * as utils from "tns-core-modules/utils/utils";
@@ -2407,11 +2407,7 @@ firebase.firestore.getCollection = (collectionPath: string): Promise<firestore.Q
24072407
const docSnapshots: Array<firestore.DocumentSnapshot> = [];
24082408
for (let i = 0; i < result.size(); i++) {
24092409
const documentSnapshot: com.google.firebase.firestore.DocumentSnapshot = result.getDocuments().get(i);
2410-
docSnapshots.push({
2411-
id: documentSnapshot.getId(),
2412-
exists: true,
2413-
data: () => firebase.toJsObject(documentSnapshot.getData())
2414-
});
2410+
docSnapshots.push(new DocumentSnapshot(documentSnapshot.getId(), true, () => firebase.toJsObject(documentSnapshot.getData())));
24152411
}
24162412
const snap = new QuerySnapshot();
24172413
snap.docSnapshots = docSnapshots;
@@ -2460,11 +2456,7 @@ firebase.firestore.getDocument = (collectionPath: string, documentPath: string):
24602456
reject(ex && ex.getReason ? ex.getReason() : ex);
24612457
} else {
24622458
const result: com.google.firebase.firestore.DocumentSnapshot = task.getResult();
2463-
resolve({
2464-
id: result ? result.getId() : null,
2465-
exists: !!result,
2466-
data: () => result ? firebase.toJsObject(result.getData()) : null
2467-
});
2459+
resolve(new DocumentSnapshot(result ? result.getId() : null, !!result, () => result ? firebase.toJsObject(result.getData()) : null));
24682460
}
24692461
}
24702462
});
@@ -2501,11 +2493,7 @@ firebase.firestore._getQuery = (collectionPath: string, query: com.google.fireba
25012493
const docSnapshots: Array<firestore.DocumentSnapshot> = [];
25022494
for (let i = 0; i < result.size(); i++) {
25032495
const documentSnapshot: com.google.firebase.firestore.DocumentSnapshot = result.getDocuments().get(i);
2504-
docSnapshots.push({
2505-
id: documentSnapshot.getId(),
2506-
exists: true,
2507-
data: () => firebase.toJsObject(documentSnapshot.getData())
2508-
});
2496+
docSnapshots.push(new DocumentSnapshot(documentSnapshot.getId(), true, () => firebase.toJsObject(documentSnapshot.getData())));
25092497
}
25102498
const snap = new QuerySnapshot();
25112499
snap.docSnapshots = docSnapshots;

src/firebase.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ export namespace firestore {
807807
get: () => Promise<DocumentSnapshot>;
808808
update: (document: any) => Promise<void>;
809809
delete: () => Promise<void>;
810+
// onSnapshot(callback: (doc: DocumentSnapshot) => void): void;
810811
}
811812

812813
export interface Query {

src/firebase.ios.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,7 @@ firebase.firestore.doc = (collectionPath: string, documentPath?: string): firest
22602260
get: () => firebase.firestore.getDocument(collectionPath, fIRDocumentReference.documentID),
22612261
update: (data: any) => firebase.firestore.update(collectionPath, fIRDocumentReference.documentID, data),
22622262
delete: () => firebase.firestore.delete(collectionPath, fIRDocumentReference.documentID)
2263+
// onSnapshot: (callback: (doc: DocumentSnapshot) => void) => firebase.firestore.onSnapshot(fIRDocumentReference, callback)
22632264
};
22642265

22652266
} catch (ex) {
@@ -2268,6 +2269,12 @@ firebase.firestore.doc = (collectionPath: string, documentPath?: string): firest
22682269
}
22692270
};
22702271

2272+
// firebase.firestore.onSnapshot = (docRef: FIRDocumentReference, callback: (doc: DocumentSnapshot) => void): void => {
2273+
// docRef.addSnapshotListener((snapshot: FIRDocumentSnapshot, error: NSError) => {
2274+
// callback(new DocumentSnapshot(snapshot ? snapshot.documentID : null, !!snapshot, snapshot ? firebase.toJsObject(snapshot.data()) : null));
2275+
// })
2276+
// };
2277+
22712278
firebase.firestore.add = (collectionPath: string, document: any): Promise<firestore.DocumentReference> => {
22722279
return new Promise((resolve, reject) => {
22732280
try {
@@ -2411,11 +2418,7 @@ firebase.firestore.getCollection = (collectionPath: string): Promise<firestore.Q
24112418
const docSnapshots: Array<firestore.DocumentSnapshot> = [];
24122419
for (let i = 0, l = snapshot.documents.count; i < l; i++) {
24132420
const document: FIRDocumentSnapshot = snapshot.documents.objectAtIndex(i);
2414-
docSnapshots.push({
2415-
id: document.documentID,
2416-
exists: true,
2417-
data: () => firebase.toJsObject(document.data())
2418-
});
2421+
docSnapshots.push(new DocumentSnapshot(document.documentID, true, () => firebase.toJsObject(document.data())));
24192422
}
24202423
const snap = new QuerySnapshot();
24212424
snap.docSnapshots = docSnapshots;
@@ -2449,11 +2452,7 @@ firebase.firestore.getDocument = (collectionPath: string, documentPath: string):
24492452
if (error) {
24502453
reject(error.localizedDescription);
24512454
} else {
2452-
resolve({
2453-
id: snapshot ? snapshot.documentID : null,
2454-
exists: !!snapshot,
2455-
data: () => snapshot ? firebase.toJsObject(snapshot.data()) : null
2456-
});
2455+
resolve(new DocumentSnapshot(snapshot ? snapshot.documentID : null, !!snapshot, () => snapshot ? firebase.toJsObject(snapshot.data()) : null));
24572456
}
24582457
});
24592458

@@ -2475,11 +2474,7 @@ firebase.firestore._getQuery = (collectionPath: string, query: FIRQuery): firest
24752474
const docSnapshots: Array<firestore.DocumentSnapshot> = [];
24762475
for (let i = 0, l = snapshot.documents.count; i < l; i++) {
24772476
const document: FIRDocumentSnapshot = snapshot.documents.objectAtIndex(i);
2478-
docSnapshots.push({
2479-
id: document.documentID,
2480-
exists: true,
2481-
data: () => firebase.toJsObject(document.data())
2482-
});
2477+
docSnapshots.push(new DocumentSnapshot(document.documentID, true, () => firebase.toJsObject(document.data())));
24832478
}
24842479
const snap = new QuerySnapshot();
24852480
snap.docSnapshots = docSnapshots;

0 commit comments

Comments
 (0)