Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular SwUpdate activated deprecation

In my angular project I have this kind of code:

this.swUpdate.available.subscribe(() => {
  ...
});

It work fine but gives me the warning about activated being deprecated.

What should I do to fix this warning?

like image 829
MahdiJoon Avatar asked Jul 13 '26 13:07

MahdiJoon


2 Answers

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,
  })));
like image 65
Roobot Avatar answered Jul 15 '26 05:07

Roobot


You must change activated to activateUpdate() and treat it as Promise:

this.swUpdate.activateUpdate().then(() => {
 ...
});
like image 45
MahdiJoon Avatar answered Jul 15 '26 04:07

MahdiJoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!