[internals] Start refactoring some of the internals to simplify, tidy up and also reduce flow type pollution

This commit is contained in:
Chris Bianca
2017-12-22 15:24:31 +00:00
parent 1a35d8a7b5
commit f2c2007fdc
30 changed files with 563 additions and 610 deletions

View File

@@ -5,6 +5,7 @@
import CollectionReference from './CollectionReference';
import DocumentSnapshot from './DocumentSnapshot';
import { buildNativeMap } from './utils/serialize';
import { getAppEventName, SharedEventEmitter } from '../../utils/events';
import { firestoreAutoId, isFunction, isObject, isString } from '../../utils';
import type Firestore from './';
@@ -136,15 +137,15 @@ export default class DocumentReference {
};
// Listen to snapshot events
this._firestore.on(
this._firestore._getAppEventName(`onDocumentSnapshot:${listenerId}`),
SharedEventEmitter.addListener(
getAppEventName(this._firestore, `onDocumentSnapshot:${listenerId}`),
listener,
);
// Listen for snapshot error events
if (observer.error) {
this._firestore.on(
this._firestore._getAppEventName(`onDocumentSnapshotError:${listenerId}`),
SharedEventEmitter.addListener(
getAppEventName(this._firestore, `onDocumentSnapshotError:${listenerId}`),
observer.error,
);
}
@@ -197,8 +198,8 @@ export default class DocumentReference {
*/
_offDocumentSnapshot(listenerId: string, listener: Function) {
this._firestore.log.info('Removing onDocumentSnapshot listener');
this._firestore.removeListener(this._firestore._getAppEventName(`onDocumentSnapshot:${listenerId}`), listener);
this._firestore.removeListener(this._firestore._getAppEventName(`onDocumentSnapshotError:${listenerId}`), listener);
SharedEventEmitter.removeListener(getAppEventName(this._firestore, `onDocumentSnapshot:${listenerId}`), listener);
SharedEventEmitter.removeListener(getAppEventName(this._firestore, `onDocumentSnapshotError:${listenerId}`), listener);
this._firestore._native
.documentOffSnapshot(this.path, listenerId);
}