mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 08:42:08 +10:00
Firebase Stub: resolving ESLint errors
This commit is contained in:
@ -1,7 +1,5 @@
|
|||||||
import Reference from './reference';
|
|
||||||
|
|
||||||
class DataSnapshot {
|
class DataSnapshot {
|
||||||
constructor(eventType, reference, value = undefined) {
|
constructor(eventType, getDataCallback, value = undefined) {
|
||||||
if (!eventType) {
|
if (!eventType) {
|
||||||
throw new Error('eventType must be provided.');
|
throw new Error('eventType must be provided.');
|
||||||
} else if (typeof eventType !== 'string') {
|
} else if (typeof eventType !== 'string') {
|
||||||
@ -10,13 +8,13 @@ class DataSnapshot {
|
|||||||
|
|
||||||
this.eventTypeField = eventType;
|
this.eventTypeField = eventType;
|
||||||
|
|
||||||
if (!reference) {
|
if (!getDataCallback) {
|
||||||
throw new Error('reference must be provided.');
|
throw new Error('getDataCallback must be provided.');
|
||||||
} else if (!(reference instanceof Reference)) {
|
} else if (typeof getDataCallback !== 'function') {
|
||||||
throw new Error('reference must be an instance of the Reference class.');
|
throw new Error('getDataCallback should be a function.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.referenceField = reference;
|
this.getDataCallbackField = getDataCallback;
|
||||||
|
|
||||||
this.valueField = value;
|
this.valueField = value;
|
||||||
}
|
}
|
||||||
@ -33,7 +31,7 @@ class DataSnapshot {
|
|||||||
if (this.eventType === 'value') {
|
if (this.eventType === 'value') {
|
||||||
return typeof this.value !== 'undefined'
|
return typeof this.value !== 'undefined'
|
||||||
? this.value
|
? this.value
|
||||||
: this.referenceField.getData();
|
: this.getDataCallbackField();
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import DataSnapshot from './dataSnapshot';
|
|||||||
const rootPath = '.';
|
const rootPath = '.';
|
||||||
|
|
||||||
class Reference {
|
class Reference {
|
||||||
constructor(path, getDatabaseData) {
|
constructor(path, getDatabaseDataCallback) {
|
||||||
if (typeof path === 'undefined' || path === null) {
|
if (typeof path === 'undefined' || path === null) {
|
||||||
this.pathField = rootPath;
|
this.pathField = rootPath;
|
||||||
} else if (typeof path !== 'string') {
|
} else if (typeof path !== 'string') {
|
||||||
@ -16,15 +16,16 @@ class Reference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.uuidField = uuidv4();
|
this.uuidField = uuidv4();
|
||||||
|
|
||||||
this.dataSnapshotsField = {};
|
this.dataSnapshotsField = {};
|
||||||
|
|
||||||
if (!getDatabaseData) {
|
if (!getDatabaseDataCallback) {
|
||||||
throw new Error('getDatabaseData must be provided.');
|
throw new Error('getDatabaseDataCallback must be provided.');
|
||||||
} else if (typeof getDatabaseData !== 'function') {
|
} else if (typeof getDatabaseDataCallback !== 'function') {
|
||||||
throw new Error('getDatabaseData should be a function.');
|
throw new Error('getDatabaseDataCallback should be a function.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getDatabaseDataField = getDatabaseData;
|
this.getDatabaseDataCallbackField = getDatabaseDataCallback;
|
||||||
|
|
||||||
this.orderByChildPathField = '';
|
this.orderByChildPathField = '';
|
||||||
this.equalToValueField = '';
|
this.equalToValueField = '';
|
||||||
@ -39,7 +40,7 @@ class Reference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getData() {
|
getData() {
|
||||||
const databaseData = this.getDatabaseDataField();
|
const databaseData = this.getDatabaseDataCallbackField();
|
||||||
|
|
||||||
if (!databaseData) {
|
if (!databaseData) {
|
||||||
return null;
|
return null;
|
||||||
@ -99,19 +100,19 @@ class Reference {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot = new DataSnapshot(eventType, this, null);
|
let snapshot = new DataSnapshot(eventType, () => this.getData(), null);
|
||||||
|
|
||||||
if (this.path === DatabaseConstants.connectedPath) {
|
if (this.path === DatabaseConstants.connectedPath) {
|
||||||
snapshot = new DataSnapshot(eventType, this, true);
|
snapshot = new DataSnapshot(eventType, () => this.getData(), true);
|
||||||
} else if (this.path === DatabaseConstants.resumesPath) {
|
} else if (this.path === DatabaseConstants.resumesPath) {
|
||||||
snapshot = new DataSnapshot(eventType, this);
|
snapshot = new DataSnapshot(eventType, () => this.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(snapshot);
|
callback(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
async once(eventType) {
|
async once(eventType) {
|
||||||
const newDataSnapshot = new DataSnapshot(eventType, this);
|
const newDataSnapshot = new DataSnapshot(eventType, () => this.getData());
|
||||||
const existingDataSnapshot = this.dataSnapshotsField[
|
const existingDataSnapshot = this.dataSnapshotsField[
|
||||||
newDataSnapshot.eventType
|
newDataSnapshot.eventType
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user