【发布时间】:2022-04-30 01:19:49
【问题描述】:
我们实施了网络检查作为窗口事件在线和离线的副作用。
online$ = createEffect(() => {
return fromEvent(window, 'online').pipe(mapTo(NetworkActions.deviceOnline()));
});
这在桌面 Chrome 和 iOS Safari 上运行良好,但不知何故会在 Android 上导致 strictActionWithinNgZone 运行时检查:
{
"state": {
"keyboard": {
"isKeyboardOpen": false
},
"network": {
"isDeviceOnline": true
}
},
"error": "Error: Action '[Network] Device Online' running outside NgZone. https://ngrx.io/guide/store/configuration/runtime-checks#strictactionwithinngzone"
},
有谁知道为什么这只发生在 Android 中以及为什么它甚至是一个问题?
编辑: 据我了解,fromEvent(window, '...') 应该始终在区域内,因为 zone.js 确实修补了所有浏览器 EventTarget。
这也适用于 Ionic + Cordova 应用程序,但仅限于在 Android 上构建时。我能看到差异的唯一原因可能在于它正在运行的 Webview 中,但除此之外它只是基本的 RxJS 和 Angular
谢谢帕斯卡
【问题讨论】:
标签: ngrx ngrx-store