在 Firebase 云函数中的 Deltasnapshot 中获取增量
Get delta in Deltasnapshot in Firebase cloud function
我在 firebase 云函数中使用 onUpdate 触发器。
exports.addInvitation = functions.database.ref(`eventList/{pushId}/invitations`).onUpdate(event => {
console.log(event.data.val())
console.log(event.data.delta())
})
with event.data.val
我可以访问更改后的值。使用 event.data.previous
我可以访问更新前的值。但是反正有没有我只能找零钱了。在 firebase 中记录 event.data.delta
我看到:
首先,我想你的意思是"With event.data.previous
I can access the value before the update"。
您在转储中看到的增量 属性 不是 DeltaSnapshot 的 public API 的一部分。所以我不建议深入研究它,因为它可能会在没有通知的情况下发生变化。
要查明 DeltaSnapshot 中的某些数据是否已更改,您应该使用 changed() 方法。或者,您可以自己比较 event.data.val()
和 event.data.previous.val()
。
我在 firebase 云函数中使用 onUpdate 触发器。
exports.addInvitation = functions.database.ref(`eventList/{pushId}/invitations`).onUpdate(event => {
console.log(event.data.val())
console.log(event.data.delta())
})
with event.data.val
我可以访问更改后的值。使用 event.data.previous
我可以访问更新前的值。但是反正有没有我只能找零钱了。在 firebase 中记录 event.data.delta
我看到:
首先,我想你的意思是"With event.data.previous
I can access the value before the update"。
您在转储中看到的增量 属性 不是 DeltaSnapshot 的 public API 的一部分。所以我不建议深入研究它,因为它可能会在没有通知的情况下发生变化。
要查明 DeltaSnapshot 中的某些数据是否已更改,您应该使用 changed() 方法。或者,您可以自己比较 event.data.val()
和 event.data.previous.val()
。