本文介绍了firebase 8.4使我的.once()持续触发[原为:firebase 8.4使我的onclick事件持续触发]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已经运行了多年.与[email protected]正常工作

My application has been working for years. Works fine with [email protected]

如果升级到[email protected](使用.0/.1/.2/.3测试),则会发生奇怪的事情.当我单击一个按钮时,onclick事件将一直触发直到出现堆栈溢出:

If upgraded to [email protected] (tested with .0/.1/.2/.3), a strange thing happens. When I click a button, the onclick event keep firing until a get a stack overflow:

FIREBASE WARNING: Exception was thrown by user callback. RangeError: Maximum call stack size exceeded

因此,我坚持使用8.3.关于如何规避此事的任何建议?

Therefore I am staying on 8.3. Any suggestions on how to circumvent this?

平台:

  • Angular Core 11.2.12
  • Angular Fire 6.1.4
  • 角材料11.2.11
  • coreJS 3.11.1
  • rxjs 6.6.7
  • tslib 2.2.0
  • 0.11.3区

模板HTML就是这样

          <button
            (click)='buStateClick(r.myKey, 1)'
            [ngStyle]="{'background-color': r.state === 1 ? 'yellow' : 'transparent'}"
          >

buStateClick()切换状态.在8.3中,每当我单击该按钮时,它将立即在黄色(突出显示)和正常之间切换.在8.4中,四秒钟没有发生任何事情,然后按钮在两种颜色之间多次切换.

buStateClick() toggles the state.In 8.3 each time I click the button, it will immediately change between yellow (highlight) and normal. In 8.4, four seconds passed without anything happened, then the button toggle between the two colors many times.

简化代码:

public buStateClick(key: string, action: state) {
    console.log('enter');
    this._afDB.database.ref(`${path}/${key}/state`).off(); // added per comment below
    this._afDB.database.ref(`${path}/${key}/state`).once('value', (snap) => {
      console.log('once');
      if (snap.exists()) {
        // code to determine newState
        this._afDB.database.ref(`${path}/${key}`).update({state: newState}).finally(() => {
          console.log('finally');
        });
      } else {
        console.warn('state not found: ${key}');
      }
    });
}

我的功能仅输入一次..once()被触发710次.update()的.finally()被触发706次.

My function is entered only once. The .once() is fired 710 times. The .finally() of the update() is triggered 706 times.

因此问题变成了:.once()中的.update()触发.once()重复执行.因此,问题标题的更改.

So the question becomes: .update() inside .once() trigger the .once() to execute repeatedly. Thus the change in question title.

如果我在.once()中添加了.off(),那么情况将恢复正常.该代码执行一次,而不是执行700多次.

If I added the .off() inside .once() then things are back to normal. The code is executed once instead of 700+ times.

亚历克斯

推荐答案

自从8.3.2迁移到8.3.3以来,我也已经开始收到超出最大调用堆栈大小"的信息.我有一个.once侦听器函数,但是在调用.update之后,由于某种原因,.once侦听器正在重新启动.我改回到8.3.2,.once侦听器仅正确触发一次.Firebase源代码中发生了一些更改,由于该错误不断发生,我现在无法移至更高版本.

Since moving from 8.3.2 to 8.3.3, i too have started receiving the "Maximum call stack size exceeded". I have a .once listener function but after a call to .update, the .once listener is re-firing for some reason. I changed back to 8.3.2 and the .once listener correctly fires only once. Something changed in the firebase source and I cannot now move to a later version because this error keeps on happening.

这篇关于firebase 8.4使我的.once()持续触发[原为:firebase 8.4使我的onclick事件持续触发]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 17:31