|
58 | 58 | "body": [
|
59 | 59 | "import { Injectable } from '@angular/core';",
|
60 | 60 | "",
|
61 |
| - "@Injectable({providedIn: ${2:'root'}})", |
62 |
| - "export class ${1:ServiceName}Service {", |
| 61 | + "@Injectable({providedIn: ${1:'root'}})", |
| 62 | + "export class ${2:ServiceName}Service {", |
63 | 63 | "\tconstructor() { }",
|
64 | 64 | "\t$0",
|
65 | 65 | "}"
|
|
125 | 125 | "import { Injectable } from '@angular/core';",
|
126 | 126 | "import { HttpClient } from '@angular/common/http';",
|
127 | 127 | "",
|
128 |
| - "@Injectable({providedIn: ${2:'root'}})", |
129 |
| - "export class ${1:ServiceName}Service {", |
| 128 | + "@Injectable({providedIn: ${1:'root'}})", |
| 129 | + "export class ${2:ServiceName}Service {", |
130 | 130 | "\tconstructor(private httpClient: HttpClient) { }",
|
131 | 131 | "\t$0",
|
132 | 132 | "}"
|
|
297 | 297 | "import { Injectable } from '@angular/core';",
|
298 | 298 | "import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';",
|
299 | 299 | "",
|
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 {", |
302 | 302 | "\tconstructor() { }",
|
303 | 303 | "",
|
304 | 304 | "\tcanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {",
|
|
314 | 314 | "import { Injectable } from '@angular/core';",
|
315 | 315 | "import { ActivatedRouteSnapshot, CanActivateChild, RouterStateSnapshot } from '@angular/router';",
|
316 | 316 | "",
|
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 {", |
319 | 319 | "\tconstructor() { }",
|
320 | 320 | "",
|
321 | 321 | "\tcanActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {",
|
|
331 | 331 | "import { Injectable } from '@angular/core';",
|
332 | 332 | "import { CanLoad, Route } from '@angular/router';",
|
333 | 333 | "",
|
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 {", |
336 | 336 | "\tconstructor() { }",
|
337 | 337 | "",
|
338 | 338 | "\tcanLoad(route: Route) {",
|
|
372 | 372 | "}"
|
373 | 373 | ]
|
374 | 374 | },
|
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", |
378 | 378 | "body": [
|
379 | 379 | "import { PreloadingStrategy, Route } from '@angular/router';",
|
380 | 380 | "import { Observable, of } from 'rxjs';",
|
|
387 | 387 | "$0"
|
388 | 388 | ]
|
389 | 389 | },
|
| 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 | + }, |
390 | 424 | "Angular Router Events": {
|
391 | 425 | "prefix": "a-router-events",
|
392 | 426 | "description": "Angular Router Events",
|
|
436 | 470 | "import { Resolve, ActivatedRouteSnapshot } from '@angular/router';",
|
437 | 471 | "import { Observable } from 'rxjs';",
|
438 | 472 | "",
|
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} {", |
442 | 476 | "\t\treturn ${0};",
|
443 | 477 | "\t}",
|
444 | 478 | "}"
|
|
567 | 601 | "} from '@ngrx/data';",
|
568 | 602 | "import { ${1:Model} } from '${2:../core}';",
|
569 | 603 | "",
|
570 |
| - "@Injectable({ providedIn: 'root' })", |
| 604 | + "@Injectable({ providedIn: ${3:'root'} })", |
571 | 605 | "export class ${1:Model}Service extends EntityCollectionServiceBase<${1:Model}> {",
|
572 | 606 | " constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {",
|
573 | 607 | " super('${1:Model}', serviceElementsFactory);",
|
|
0 commit comments