Skip to content

Commit adbefe7

Browse files
authored
v9
1 parent ad5a97d commit adbefe7

File tree

5 files changed

+103
-53
lines changed

5 files changed

+103
-53
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
## Angular Snippets Changelog
22

3+
<a name="9.0.0"></a>
4+
5+
# 9.0.0 (2020-02-10)
6+
7+
Changes
8+
9+
- Revise all providedIn snippets to prompt user for a value
10+
- Update `a-http-interceptor-logging` for RxJS move (#107)
11+
- Update ngrx effects - wrap with return (#100)
12+
- Various interceptor fixes
13+
- Revised routing module to be part of regular module
14+
- Added `a-preload-opt-in-strategy` as a custom preload strategy that allows choosing which routes to preload
15+
- Added `a-preload-network-strategy` as a custom preload strategy that preloads based on network connectivity
16+
317
<a name="8.3.1"></a>
418

519
# 8.3.1 (2020-02-01)

README.md

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,41 @@ Alternatively, press `Ctrl`+`Space` (Windows, Linux) or `Cmd`+`Space` (macOS) to
2626

2727
### TypeScript Angular Snippets
2828

29-
| Snippet | Purpose |
30-
| ---------------------------- | ------------------------------------------------------------ |
31-
| `a-component` | component |
32-
| `a-component-inline` | component with inline template |
33-
| `a-component-root` | root app component |
34-
| `a-directive` | directive |
35-
| `a-guard-can-activate` | `CanActivate` guard |
36-
| `a-guard-can-activate-child` | `CanActivateChild` guard |
37-
| `a-guard-can-deactivate` | `CanDeactivate` guard |
38-
| `a-guard-can-load` | `CanLoad` guard |
39-
| `a-httpclient-get` | `httpClient.get` with Rx Observable |
40-
| `a-http-interceptor` | Empty Angular `HttpInterceptor` for `HttpClient` |
41-
| `a-http-interceptor-headers` | Angular `HttpInterceptor` that sets headers for `HttpClient` |
42-
| `a-http-interceptor-logging` | Angular `HttpInterceptor` that logs traffic for `HttpClient` |
43-
| `a-module` | module |
44-
| `a-module-root` | root app module |
45-
| `a-module-routing` | routing module file (forChild) |
46-
| `a-output-event` | `@Output` event and emitter |
47-
| `a-pipe` | pipe |
48-
| `a-resolver` | resolver |
49-
| `a-rxjs-import` | import RxJs features |
50-
| `a-rxjs-operators` | import RxJs operators |
51-
| `a-route-path-404` | 404 route path |
52-
| `a-route-path-default` | default route path |
53-
| `a-route-path-with-children` | route path with children |
54-
| `a-route-path-eager` | eager route path |
55-
| `a-route-path-lazy` | lazy route path |
56-
| `a-router-events` | listen to one or more router events |
57-
| `a-route-params-subscribe` | subscribe to route parameters |
58-
| `a-service` | service with injectable provided in root |
59-
| `a-service-httpclient` | service with `HttpClient` |
60-
| `a-ctor-skip-self` | angular `NgModule`'s `skipself` constructor |
61-
| `a-subscribe` | Rx Observable subscription |
29+
| Snippet | Purpose |
30+
| ---------------------------- | -------------------------------------------------------------------- |
31+
| `a-component` | component |
32+
| `a-component-inline` | component with inline template |
33+
| `a-component-root` | root app component |
34+
| `a-directive` | directive |
35+
| `a-guard-can-activate` | `CanActivate` guard |
36+
| `a-guard-can-activate-child` | `CanActivateChild` guard |
37+
| `a-guard-can-deactivate` | `CanDeactivate` guard |
38+
| `a-guard-can-load` | `CanLoad` guard |
39+
| `a-httpclient-get` | `httpClient.get` with Rx Observable |
40+
| `a-http-interceptor` | Empty Angular `HttpInterceptor` for `HttpClient` |
41+
| `a-http-interceptor-headers` | Angular `HttpInterceptor` that sets headers for `HttpClient` |
42+
| `a-http-interceptor-logging` | Angular `HttpInterceptor` that logs traffic for `HttpClient` |
43+
| `a-module` | module |
44+
| `a-module-root` | root app module |
45+
| `a-module-routing` | routing module file (forChild) |
46+
| `a-output-event` | `@Output` event and emitter |
47+
| `a-pipe` | pipe |
48+
| `a-preload-opt-in-strategy` | custom preload strategy that allows choosing which routes to preload |
49+
| `a-preload-network-strategy` | custom preload strategy that preloads based on network connectivity |
50+
| `a-resolver` | resolver |
51+
| `a-rxjs-import` | import RxJs features |
52+
| `a-rxjs-operators` | import RxJs operators |
53+
| `a-route-path-404` | 404 route path |
54+
| `a-route-path-default` | default route path |
55+
| `a-route-path-with-children` | route path with children |
56+
| `a-route-path-eager` | eager route path |
57+
| `a-route-path-lazy` | lazy route path |
58+
| `a-router-events` | listen to one or more router events |
59+
| `a-route-params-subscribe` | subscribe to route parameters |
60+
| `a-service` | service with injectable provided in root |
61+
| `a-service-httpclient` | service with `HttpClient` |
62+
| `a-ctor-skip-self` | angular `NgModule`'s `skipself` constructor |
63+
| `a-subscribe` | Rx Observable subscription |
6264

6365
### NgRx Snippets
6466

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"keywords": [
1717
"Angular",
1818
"Angular 2",
19-
"Angular 8",
19+
"Angular 9",
2020
"TypeScript",
2121
"HTML"
2222
],
23-
"version": "8.3.1",
23+
"version": "9.0.0",
2424
"engines": {
2525
"vscode": "^1.40.0"
2626
},

snippets/typescript.json

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
"body": [
5959
"import { Injectable } from '@angular/core';",
6060
"",
61-
"@Injectable({providedIn: ${2:'root'}})",
62-
"export class ${1:ServiceName}Service {",
61+
"@Injectable({providedIn: ${1:'root'}})",
62+
"export class ${2:ServiceName}Service {",
6363
"\tconstructor() { }",
6464
"\t$0",
6565
"}"
@@ -125,8 +125,8 @@
125125
"import { Injectable } from '@angular/core';",
126126
"import { HttpClient } from '@angular/common/http';",
127127
"",
128-
"@Injectable({providedIn: ${2:'root'}})",
129-
"export class ${1:ServiceName}Service {",
128+
"@Injectable({providedIn: ${1:'root'}})",
129+
"export class ${2:ServiceName}Service {",
130130
"\tconstructor(private httpClient: HttpClient) { }",
131131
"\t$0",
132132
"}"
@@ -297,8 +297,8 @@
297297
"import { Injectable } from '@angular/core';",
298298
"import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';",
299299
"",
300-
"@Injectable({providedIn: ${2:'root'}})",
301-
"export class ${1:Name}Guard implements CanActivate {",
300+
"@Injectable({providedIn: ${1:'root'}})",
301+
"export class ${2:Name}Guard implements CanActivate {",
302302
"\tconstructor() { }",
303303
"",
304304
"\tcanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {",
@@ -314,8 +314,8 @@
314314
"import { Injectable } from '@angular/core';",
315315
"import { ActivatedRouteSnapshot, CanActivateChild, RouterStateSnapshot } from '@angular/router';",
316316
"",
317-
"@Injectable({providedIn: ${2:'root'}})",
318-
"export class ${1:Name}Guard implements CanActivateChild {",
317+
"@Injectable({providedIn: ${1:'root'}})",
318+
"export class ${2:Name}Guard implements CanActivateChild {",
319319
"\tconstructor() { }",
320320
"",
321321
"\tcanActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {",
@@ -331,8 +331,8 @@
331331
"import { Injectable } from '@angular/core';",
332332
"import { CanLoad, Route } from '@angular/router';",
333333
"",
334-
"@Injectable({providedIn: ${2:'root'}})",
335-
"export class ${1:Name}Guard implements CanLoad {",
334+
"@Injectable({providedIn: ${1:'root'}})",
335+
"export class ${2:Name}Guard implements CanLoad {",
336336
"\tconstructor() { }",
337337
"",
338338
"\tcanLoad(route: Route) {",
@@ -372,9 +372,9 @@
372372
"}"
373373
]
374374
},
375-
"Angular Custom Preload Strategy": {
376-
"prefix": "a-preload-strategy",
377-
"description": "Angular custom preload strategy",
375+
"Angular Opt-In Preload Strategy": {
376+
"prefix": "a-preload-opt-in-strategy",
377+
"description": "Angular opt-in preload strategy",
378378
"body": [
379379
"import { PreloadingStrategy, Route } from '@angular/router';",
380380
"import { Observable, of } from 'rxjs';",
@@ -387,6 +387,40 @@
387387
"$0"
388388
]
389389
},
390+
"Angular Network-Aware Preload Strategy": {
391+
"prefix": "a-preload-network-strategy",
392+
"description": "Angular network aware preload strategy",
393+
"body": [
394+
"import { Injectable } from '@angular/core';",
395+
"import { PreloadingStrategy, Route } from '@angular/router';",
396+
"import { Observable, EMPTY } from 'rxjs';",
397+
"",
398+
"// avoid typing issues for now",
399+
"export declare var navigator;",
400+
"",
401+
"@Injectable({ providedIn: 'root' })",
402+
"export class NetworkAwarePreloadStrategy implements PreloadingStrategy {",
403+
"\tpreload(route: Route, load: () => Observable<any>): Observable<any> {",
404+
"\t\treturn this.hasGoodConnection() ? load() : EMPTY;",
405+
"\t}",
406+
"",
407+
"\thasGoodConnection(): boolean {",
408+
"\t\tconst conn = navigator.connection;",
409+
"\t\tif (conn) {",
410+
"\t\t\tif (conn.saveData) {",
411+
"\t\t\t\treturn false; // save data mode is enabled, so dont preload",
412+
"\t\t\t}",
413+
"\t\t\tconst avoidTheseConnections = ['slow-2g', '2g' /* , '3g', '4g' */];",
414+
"\t\t\tconst effectiveType = conn.effectiveType || '';",
415+
"\t\t\tif (avoidTheseConnections.includes(effectiveType)) {",
416+
"\t\t\t\treturn false;",
417+
"\t\t\t}",
418+
"\t\t}",
419+
"\t\treturn true;",
420+
"\t}",
421+
"}"
422+
]
423+
},
390424
"Angular Router Events": {
391425
"prefix": "a-router-events",
392426
"description": "Angular Router Events",
@@ -436,9 +470,9 @@
436470
"import { Resolve, ActivatedRouteSnapshot } from '@angular/router';",
437471
"import { Observable } from 'rxjs';",
438472
"",
439-
"@Injectable({ providedIn: 'root' })",
440-
"export class ${1:YourResolver} implements Resolve<${2:ObjectToResolve}> {",
441-
"\tresolve(route: ActivatedRouteSnapshot): Observable<${2:ObjectToResolve}> | Promise<${2:ObjectToResolve}> | ${2:ObjectToResolve} {",
473+
"@Injectable({ providedIn: ${1:'root'} })",
474+
"export class ${2:YourResolver} implements Resolve<${3:ObjectToResolve}> {",
475+
"\tresolve(route: ActivatedRouteSnapshot): Observable<${3:ObjectToResolve}> | Promise<${3:ObjectToResolve}> | ${3:ObjectToResolve} {",
442476
"\t\treturn ${0};",
443477
"\t}",
444478
"}"
@@ -567,7 +601,7 @@
567601
"} from '@ngrx/data';",
568602
"import { ${1:Model} } from '${2:../core}';",
569603
"",
570-
"@Injectable({ providedIn: 'root' })",
604+
"@Injectable({ providedIn: ${3:'root'} })",
571605
"export class ${1:Model}Service extends EntityCollectionServiceBase<${1:Model}> {",
572606
" constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {",
573607
" super('${1:Model}', serviceElementsFactory);",

0 commit comments

Comments
 (0)