Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
docRef.onSnapshot((docSnapshot) => {
if (this.model[modelName].record[id].hasOnSnapshotRunAtLeastOnce) {
if (docSnapshot.exists) {
const record = store.peekRecord(modelName, id);
if (record && !record.isSaving) {
const flatRecord = flattenDocSnapshotData(docSnapshot);
const normalizedRecord = store.normalize(modelName, flatRecord);
store.push(normalizedRecord);
}
} else {
this.unloadRecord(store, modelName, id);
}
} else {
this.model[modelName].record[id].hasOnSnapshotRunAtLeastOnce = true;
}
}, (error) => {
const record = store.peekRecord(modelName, id);
const unsubscribe = docRef.onSnapshot((docSnapshot) => {
if (docSnapshot.exists) {
if (this.getAdapterOptionConfig(snapshot, 'isRealtime') && !this.isFastBoot) {
this.realtimeTracker.trackFindRecordChanges(type.modelName, docRef, store);
}
resolve(flattenDocSnapshotData(docSnapshot));
} else {
reject(new Error(`Record ${id} for model type ${type.modelName} doesn't exist`));
}
unsubscribe();
}, error => reject(new Error(error.message)));
});