云功能迁移:Beta到v1.0

时间:2018-04-06 07:55:02

标签: firebase google-cloud-functions

我按照Firebase提供的指南更新了我的应用的云功能,但我不确定我是否做对了。我已将我的代码的前后版本置于其下方,如果我遗漏了任何内容,有人可以提出建议吗?

//Beta Version of the code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.countFrequency = functions.database.ref("country/{gameType}/combinationFrequencyCounter/{combinationLength}/{combinationId}/children").onWrite(event => {

    countRef = event.data.numChildren();
    key = 1000000000 - countRef;
    uniqueKey = key+"_"+event.params.combinationId;
    frequencyPushes = event.data.ref.parent.child('frequency').set(countRef);
    uniqueKeyPushes = event.data.adminRef.root.child("country/"+event.params.gameType+"/combinations/"+event.params.combinationLength+"/"+event.params.combinationId+"/uniqueKey").set(uniqueKey);
    frequency = event.data.adminRef.root.child("country/"+event.params.gameType+"/combinations/"+event.params.combinationLength+"/"+event.params.combinationId+"/frequency").set(countRef);

    return uniqueKeyPushes;

});

//v1.0 Version of the code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.countFrequency = functions.database.ref("country/{gameType}/combinationFrequencyCounter/{combinationLength}/{combinationId}/children").onWrite((change, context) => {

    countRef = change.after.numChildren();
    key = 1000000000 - countRef;
    uniqueKey = key+"_"+context.params.combinationId;
    frequencyPushes = change.after.ref.parent.child('frequency').set(countRef);
    uniqueKeyPushes = change.after.ref.root.child("country/"+context.params.gameType+"/combinations/"+context.params.combinationLength+"/"+context.params.combinationId+"/uniqueKey").set(uniqueKey);
    frequency = change.after.ref.root.child("country/"+context.params.gameType+"/combinations/"+context.params.combinationLength+"/"+context.params.combinationId+"/frequency").set(countRef);

    return uniqueKeyPushes;

});

此外,在将代码更新到v1.0后,我该怎么办?我是否只需使用" firebase deploy --only functions"上传新功能。就像我在Beta期间做的那样?

0 个答案:

没有答案