[英]How to fix ESLint Error when trying to remove service worker
Based on this answer How do I uninstall a Service Worker?基于此答案如何卸载 Service Worker? Removing service worker can be done with the bellow code:
删除 service worker 可以使用以下代码完成:
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for(let registration of registrations) {
registration.unregister()
} })
When I add it.当我添加它时。 ESLint has the following error:
ESLint 有以下错误:
error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them.
错误迭代器/生成器需要 regenerator-runtime,这对于本指南来说太重了,不允许它们。 Separately, loops should be avoided in favor of array iterations no-restricted-syntax
另外,应避免循环以支持数组迭代无限制语法
Any idea how to rewrite this code to make ESLint not complain?知道如何重写此代码以使 ESLint 不抱怨吗?
Modify the code like this, and use Object.entries/Object.keys/Object.values
depending on use-case with forEach
:像这样修改代码,并根据用例使用
Object.entries/Object.keys/Object.values
和forEach
:
navigator.serviceWorker.getRegistrations().then(function(registrations) {
Object.entries(registrations).forEach(registration =>{
registration.unregister()
}) })
From the GitHub Issue for the error you mentioned.来自您提到的错误的GitHub 问题。
You could use any of the array iterators mentioned in the link.您可以使用链接中提到的任何数组迭代器。
registrations.forEach(function (registration) {
registration.unregister();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.