sample to describe how to init sw outside#1
sample to describe how to init sw outside#1JiaLiPassion wants to merge 2 commits intoDevIntent:masterfrom
Conversation
Splaktar
left a comment
There was a problem hiding this comment.
Made a couple of comments on small changes.
One other concern:
Would going down a path similar to how preloading lazy loaded routes works be better? I.e. define a swRegistrationStrategy parameter that then has a couple of Angular provided defaults (like registerImmediately and registerWhenStable). Then allow it to also take user defined strategies similar to what https://github.com/angular/angular/blob/master/aio/content/examples/router/src/app/selective-preloading-strategy.ts does for the PreloadingStrategy.
src/app/app.component.ts
Outdated
| console.log(`The application is stable? ${status}`); | ||
| }); | ||
| if (environment.production) { | ||
| // if (environment.production) { |
There was a problem hiding this comment.
This probably doesn't need to be commented it out as it isn't related to service workers.
There was a problem hiding this comment.
yes, I just comment it for local debug, I will add it back.
src/app/app.component.ts
Outdated
|
|
||
| static getServiceWorkerInitFactory() { | ||
| return new Promise<any>((resolve, reject) => { | ||
| AppComponent.serviceWorkerResolve = resolve; |
There was a problem hiding this comment.
This will resolve immediately and trigger service worker registration immediately right? It would be nice for the example here to do something like wait 3-5 seconds and then register the service worker.
There was a problem hiding this comment.
Sure, I will update the sample.
|
@Splaktar , I have updated the sample according the the PR change angular/angular#21842, please review. |
Splaktar
left a comment
There was a problem hiding this comment.
I like the direction that this is going 😸
| import {GoogleAnalyticsService} from './google-analytics.service'; | ||
| import {isPlatformBrowser} from '@angular/common'; | ||
| import {filter} from 'rxjs/operators'; | ||
| import {Observable} from 'rxjs/Observable'; |
There was a problem hiding this comment.
Changes to this file can be reverted?
| observer.next(); | ||
| }, 10000); | ||
| }); | ||
| } |
There was a problem hiding this comment.
I think that it would be a better example to move this into a file like src/app/custom-registration-strategy.ts.
| googleAnalyticsTrackingId: '', | ||
| mapsApiKey: 'AIzaSyCG5P0ZrbWcC212QZsEebyyGwj2KRgs700' | ||
| mapsApiKey: 'AIzaSyCG5P0ZrbWcC212QZsEebyyGwj2KRgs700', | ||
| serviceWorkerStrategy: 'registerImmediately' |
There was a problem hiding this comment.
This probably isn't needed as it will have enabled: false in this case and the strategy won't be considered.
| serviceWorkerStrategy: 'registerDelay:5000' | ||
| // serviceWorkerStrategy: 'registerImmediately' | ||
| // serviceWorkerStrategy: 'registerWhenStable' | ||
| // serviceWorkerStrategy: getServiceWorkerObservable |
There was a problem hiding this comment.
I would prefer to see these commented out examples of using different strategies in the app.module.ts.
|
Closing this, as thankfully we got PR angular/angular#21842 into Angular version |
Relates to #1. Relates to angular/angular#21842.
just to describe an idea to init service-worker in app code.
the change in angular is here, angular/angular#21842