如何有效使用Firebase功能?

时间:2019-04-25 07:03:13

标签: javascript firebase google-cloud-functions

我正在将Firebase Functions用于移动项目。我从未将Firebase函数用于其他项目。我想学习有效地使用。请把您的建议和错误写给我。 我在index.js中的代码;

const load = () => {
 ....
}

const soapValidate = () => {
 ....
}

const loginParse = () => {
 ....
}

const loginValidate = () => {
 ....
}

const roomValidate = () => {
 ....
}

const roomParse = () => {
 ....
}


exports.remoteLogin = functions.https.onCall(async (data, context) => {
  ....
}


exports.setRoom = functions.https.onCall(async (data, context) => {
  ....
}

以上功能从远程服务器接收和处理数据。将会有许多类似的功能。将它们全部放入index.js文件是否有意义?在功能上分成不同的文件是否合乎逻辑?

1 个答案:

答案 0 :(得分:0)

如果使用打字稿

我通常使用打字稿。

索引
import { remoteLogin } from "./login";
import { setRoom } from "./room";


export {
  remoteLogin,
  setRoom
}
登录名
export const remoteLogin = functions.https.onCall(async (data, context) => {
  ....
}
room.ts
export const setRoom = functions.https.onCall(async (data, context) => {
  ....
}

如果使用javascript

index.js
const login = require("./login");
const room = require("./room");

exports.remoteLogin = login.remoteLogin
exports.setRoom = room.setRoom
login.js
exports.remoteLogin = functions.https.onCall(async (data, context) => {
  ....
}
room.js
exports.setRoom = functions.https.onCall(async (data, context) => {
  ....
}