I am splitting my current Firebase class in smaller fragments.
export default class Firebase {
constructor() {
if (!firebase.apps.length) {
// Initialize App
firebase.initializeApp(Constants.manifest.web.config.firebase);
// Initialize APIs
this._usersAPI = new Users();
this._contentAPI = new Content();
this._messagingAPI = new Messaging();
this._notificationsAPI = new Notifications();
}
}
get usersAPI() {
return this._usersAPI;
}
...
}
As you can see, the Firebase class is composed by smaller classes.
But, to be honest, the smalle classes seems that they don't need to be implemented as classes.
Now, I am thinking about moving them to JS Objects
export default class Auth {
constructor() {
this.auth = firebase.auth();
this.firestore = firebase.firestore();
}
/*
Persistance
*/
enableAuthPersistence() {
return this.auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL);
}
/*
Sign in/out
*/
signInWithEmailAndPassword(email, password) {
return this.auth.signInWithEmailAndPassword(email, password);
}
async signInWithUsernameAndPassword(username, password) {
...
}
signOut() {
return this.auth.signOut();
}
/*
Password
*/
resetPassword(email) {
return this.auth.sendPasswordResetEmail(email);
}
updatePassword(password) {
return this.auth.currentUser.updatePassword(password);
}
/*
Helpers
*/
parseError(errorCode) {
...
}
get currentUser() {
return this.auth.currentUser;
}
}
How can I convert them to objects? So that I do
import users from "./api/users";
...
constructor() {
...
// Initialize APIs
this._usersAPI = users;
this._contentAPI = content;
this._messagingAPI = messaging;
this._notificationsAPI = notifications;
}
...
in my Firebase class, instead of instantiating?
let userApi = new Users(); export function getUser() { /*...*/ }and so on?