【发布时间】:2020-10-11 16:46:22
【问题描述】:
我正在尝试在我的 Angular 应用程序中实现 Firebase Distributed Counter Extension,但我不太确定如何去做。说明说要在您的项目中包含sharded-counter.js 文件,它们给出了以下示例:
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/[version]/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/[version]/firebase-firestore.js"></script>
<script src="sharded-counter.js"></script>
</head>
<body>
<script>
// Initialize Firebase.
var firebaseConfig = { projectId: "at-the-dinner-table" };
firebase.initializeApp(firebaseConfig);
var db = firebase.firestore();
// Initialize the sharded counter.
var visits = new sharded.Counter(db.doc("pages/hello-world"), "visits");
// Increment the field "visits" of the document "pages/hello-world".
visits.incrementBy(1);
// Listen to locally consistent values.
visits.onSnapshot((snap) => {
console.log("Locally consistent view of visits: " + snap.data());
});
// Alternatively, if you don't mind counter delays, you can listen to the document directly.
db.doc("pages/hello-world").onSnapshot((snap) => {
console.log("Eventually consistent view of visits: " + snap.get("visits"));
});
</script>
</body>
</html>
我尝试使用import * as sharded from 'file path' 导入此文件,但随后我收到Counter 不是构造函数的消息。我确定我缺少一些东西,所以任何帮助将不胜感激!
【问题讨论】:
标签: angular typescript firebase google-cloud-firestore firebase-extensions