Mah*_*rei 5 deprecated rxjs typescript angular angular-service-worker
在我的角度项目中,我有这样的代码:
this.swUpdate.available.subscribe(() => {
...
});
Run Code Online (Sandbox Code Playgroud)
它工作正常,但给了我关于被弃用的警告activated。
我应该怎么做才能解决这个警告?
Roo*_*bot 13
I believe activated and activateUpdate() are different things. You call activateUpdate(), then when it's done, activated happens.
Furthermore, activated and available are definitely different things (your question references both). available means an update is detected; activated means it's been installed.
According to the docs (https://angular.io/api/service-worker/SwUpdate), the replacement for available is:
import {filter, map} from 'rxjs/operators';
// ...
const updatesAvailable = swUpdate.versionUpdates.pipe(
filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
map(evt => ({
type: 'UPDATE_AVAILABLE',
current: evt.currentVersion,
available: evt.latestVersion,
})));
Run Code Online (Sandbox Code Playgroud)
您必须更改activated为activateUpdate()并将其视为Promise:
this.swUpdate.activateUpdate().then(() => {
...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4051 次 |
| 最近记录: |