Есть ли способ хранить все функции базы данных firebase в одном js-файле и использовать этот файл из других js-файлов в собственном приложении реагировать? - PullRequest
0 голосов
/ 03 февраля 2019

Я создал файл js, который включает все операции с базой данных.Как я могу использовать эти функции при обновлении информации о пользователях из другого класса?Я не хочу повторять коды операций базы данных в каждом файле javascript снова и снова .

Мой файл FirebaseOperation.js выглядит следующим образом:

export default class FirebaseOperations {

 InitializeFirebase = () => {
      await firebase.initializeApp(config)
 }

 UpdateProfilePicDataFirebase = (phone) => {
      try{
      // A post entry.
      var postData = {
        profilePic: profilePic
      };

      // Get a key for a new Post.
      var newPostKey = firebase.database().ref().child('posts').push().key;

      // Write the new post's data simultaneously in the posts list and the user's post list.
      var updates = {};
      updates['/posts/' + newPostKey] = postData;
      updates['/user/' + phone + '/' + newPostKey] = postData;

      return firebase.database().ref().update(updates);
      }catch(err){
           console.log(err);
      }

 }

 UpdateBiographyDataFirebase = (phone) => {
      try{
      // A post entry.
      var postData = {
        biography: biography
      };

      // Get a key for a new Post.
      var newPostKey = firebase.database().ref().child('posts').push().key;

      // Write the new post's data simultaneously in the posts list and the user's post list.
      var updates = {};
      updates['/posts/' + newPostKey] = postData;
      updates['/user/' + phone + '/' + newPostKey] = postData;

      return firebase.database().ref().update(updates);
      }catch(err){
           console.log(err)
      }      
 }
 UpdatePasswordDataFirebase = (phone) => {
      try{
      // A post entry.
      var postData = {
        password: password
      };

      // Get a key for a new Post.
      var newPostKey = firebase.database().ref().child('posts').push().key;

      // Write the new post's data simultaneously in the posts list and the user's post list.
      var updates = {};
      updates['/posts/' + newPostKey] = postData;
      updates['/user/' + phone + '/' + newPostKey] = postData;

      return firebase.database().ref().update(updates);
      }catch(err){
           console.log(err)
      }

 }

Я хочу сделать что-то вроде этого:

В UpdateUser.js

FirebaseOperations .UpdateProfilePicDataFirebase (picture);

В App.js

FirebaseOperations.InitializeFirebase ();
...