Как преобразовать класс с элементами stati c в файл модуля - PullRequest
0 голосов
/ 27 апреля 2020

У меня есть такой класс:

export default class {
  static myConnection = GHD.initConnection();

  static getCards = () => this.myConnection.getCards();
}

И я называю его так:

import connector from '../path.js';
connector.getCards();

Я хотел бы преобразовать этот класс с элементами stati c в модуль в основном Я не хочу использовать класс. Это возможно? Я пробовал что-то вроде:

module.exports {
  myConnection: GHD.initConnection();

  getCards: () => this.myConnection.getCards();
}

, но это не работает. Обновление с реальными значениями кода, запрошенными в комментариях:

export default class {
  static firebaseReference = RNFirebase.initializeApp();

  static getDatabase = () => this.firebaseReference.database();

  static getUser = () => this.firebaseReference.auth().currentUser;
}

1 Ответ

0 голосов
/ 27 апреля 2020

Возможно, вы ищете

export const myConnection = GHD.initConnection();
export const getCards = () => myConnection.getCards();

, а затем

import * as connector from '../path.js';
connector.getCards();

или

import { getCards } from '../path.js';
getCards();

Если вы должны поддерживать совместимость с синтаксисом импорта по умолчанию, вы можно использовать

export const myConnection = GHD.initConnection();
export const getCards = () => myConnection.getCards();

/** @deprecated */
export default { myConnection, getCards };
...