Firebase Stub refactoring

This commit is contained in:
gianantoniopini
2021-01-07 18:04:59 +01:00
parent c2ac9594ef
commit 3c6e45abf4
6 changed files with 298 additions and 281 deletions

View File

@ -0,0 +1,47 @@
import Reference from './reference';
class DataSnapshot {
#eventType = '';
#reference = null;
#value = undefined;
constructor(eventType, reference, value = undefined) {
if (!eventType) {
throw new Error('eventType must be provided.');
} else if (typeof eventType !== 'string') {
throw new Error('eventType should be a string.');
}
this.#eventType = eventType;
if (!reference) {
throw new Error('reference must be provided.');
} else if (!(reference instanceof Reference)) {
throw new Error('reference must be an instance of the Reference class.');
}
this.#reference = reference;
this.#value = value;
}
get eventType() {
return this.#eventType;
}
get value() {
return this.#value;
}
val() {
if (this.eventType === 'value') {
return typeof this.value !== 'undefined'
? this.value
: this.#reference.getData();
}
return undefined;
}
}
export default DataSnapshot;