Skip to content

Commit ca7c621

Browse files
wesleygrimesjohnpapa
authored andcommitted
Add NgRx Snippets
LGTM
1 parent 28fffe9 commit ca7c621

File tree

4 files changed

+129
-28
lines changed

4 files changed

+129
-28
lines changed

CHANGELOG.md

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

3+
<a name="8.1.0"></a>
4+
5+
# 8.1.0 (2019-06-07)
6+
7+
- Added NgRx snippets for the creator functions: `createAction`, `createEffect`, `createReducer`, and `createSelector`
8+
- Updated `ngrx-data` snippets for `NgRx` version 8
9+
- Fixed display and description names for version 8
10+
- Removed `a-ngrx-data-store-module`, replaced with new `a-ngrx-store-module` and `a-ngrx-data-entity-data-module-import`
11+
312
<a name="8.0.0"></a>
413

514
# 8.0.0 (2019-06-07)

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ Alternatively, press `Ctrl`+`Space` (Windows, Linux) or `Cmd`+`Space` (OSX) to a
4343
| `a-module` | module |
4444
| `a-module-root` | root app module |
4545
| `a-module-routing` | routing module file (forChild) |
46-
| `a-ngrx-data-store-module` | create an NgRx Data store module |
46+
| `a-ngrx-store-module` | create an NgRx store module |
47+
| `a-ngrx-create-action` | create an NgRx action with `createAction` |
48+
| `a-ngrx-create-action-props` | create an NgRx action with `createAction` with props |
49+
| `a-ngrx-create-reducer` | create an NgRx reducer with `createReducer` |
50+
| `a-ngrx-create-effect` | create an NgRx effect with `createEffect` |
51+
| `a-ngrx-create-effect-api` | create an NgRx effect with `createEffect` for an API call |
52+
| `a-ngrx-create-selector` | create an NgRx selector with `createSelector` |
53+
| `a-ngrx-create-selector-props` | create an NgRx selector with `createSelector` with props |
54+
| `a-ngrx-data-entity-data-module-import` | add `EntityDataModule` |
4755
| `a-ngrx-data-entity-metadata` | create the entity metadata for NgRx |
4856
| `a-ngrx-data-entity-collection-data-service` | create a data service using NgRx |
4957
| `a-output-event` | `@Output` event and emitter |
@@ -116,3 +124,10 @@ Alternatively, press `Ctrl`+`Space` (Windows, Linux) or `Cmd`+`Space` (OSX) to a
116124
1. Select `Install Extension`
117125
1. Choose the extension
118126
1. Reload Visual Studio Code
127+
128+
## Credits
129+
130+
Thanks to the following contributors for the NgRx snippets:
131+
132+
- [Wes Grimes](https://twitter.com/wesgrimes)
133+
- [Tim Deschryver](https://twitter.com/tim_deschryver)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"TypeScript",
2121
"HTML"
2222
],
23-
"version": "8.0.0",
23+
"version": "8.1.0",
2424
"engines": {
2525
"vscode": "^1.20.0"
2626
},

snippets/typescript.json

Lines changed: 103 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -436,34 +436,127 @@
436436
"description": "RxJs import",
437437
"body": ["import { ${1:map} } from 'rxjs/operators';", "$0"]
438438
},
439-
"NgRx Data Module": {
440-
"prefix": "a-ngrx-data-store-module",
441-
"description": "NgRx Data Store Module",
439+
"Angular Resolver": {
440+
"prefix": "a-resolver",
441+
"description": "Angular Resolver",
442+
"body": [
443+
"import { Injectable } from '@angular/core';",
444+
"import { Resolve, ActivatedRouteSnapshot } from '@angular/router';",
445+
"import { Observable } from 'rxjs';",
446+
"",
447+
"@Injectable({ providedIn: 'root' })",
448+
"export class ${1:YourResolver} implements Resolve<${2:ObjectToResolve}> {",
449+
"\tresolve(route: ActivatedRouteSnapshot): Observable<${2:ObjectToResolve}> | Promise<${2:ObjectToResolve}> | ${2:ObjectToResolve} {",
450+
"\t\treturn ${0};",
451+
"\t}",
452+
"}"
453+
]
454+
},
455+
"NgRx Store Module": {
456+
"prefix": "a-ngrx-store-module",
457+
"description": "NgRx Store Module",
442458
"body": [
443459
"import { NgModule } from '@angular/core';",
444460
"import { EffectsModule } from '@ngrx/effects';",
445461
"import { StoreModule } from '@ngrx/store';",
446462
"import { StoreDevtoolsModule } from '@ngrx/store-devtools';",
447-
"import { NgrxDataModule } from 'ngrx-data';",
448463
"import { environment } from '../../environments/environment';",
449-
"import { entityConfig } from './entity-metadata';",
450464
"",
451465
"@NgModule({",
452466
" imports: [",
453467
" StoreModule.forRoot({}),",
454468
" EffectsModule.forRoot([]),",
455-
" environment.production ? [] : StoreDevtoolsModule.instrument(),",
456-
" NgrxDataModule.forRoot(entityConfig)",
469+
" environment.production ? [] : StoreDevtoolsModule.instrument()",
457470
" ]",
458471
"})",
459-
"export class AppStoreModule {}"
472+
"export class $1StoreModule {}"
473+
]
474+
},
475+
"NgRx Create Action": {
476+
"prefix": "a-ngrx-create-action",
477+
"description": "Creates an NgRx Action",
478+
"body": [
479+
"export const ${1:action} = createAction('[${2:Source}] ${3:Event}');"
480+
]
481+
},
482+
"NgRx Create Action w/ Props": {
483+
"prefix": "a-ngrx-create-action-props",
484+
"description": "Creates an NgRx Action with Props",
485+
"body": [
486+
"export const ${1:action} = createAction('[${2:Source}] ${3:Event}', props<{${4:key}: ${5:type}}>());"
487+
]
488+
},
489+
"NgRx Create Reducer": {
490+
"prefix": "a-ngrx-create-reducer",
491+
"description": "Creates an NgRx Reducer",
492+
"body": [
493+
"const ${1:feature}Reducer = createReducer(",
494+
"\tintialState,",
495+
"\ton($1Actions.action, state => ({ ...state, ${2:prop}: ${3:updatedValue} })),",
496+
");",
497+
"",
498+
"export function reducer(state: State | undefined: action: Action) {",
499+
"\treturn $1Reducer(state, action);",
500+
"}"
501+
]
502+
},
503+
"NgRx Create Effect": {
504+
"prefix": "a-ngrx-create-effect",
505+
"description": "Creates an NgRx Effect",
506+
"body": [
507+
"${1:effectName}$ = createEffect(() => this.actions$.pipe(",
508+
"\tofType(${2:action}.type),",
509+
"\t/** An EMPTY observable only emits completion. Replace with your own observable stream */",
510+
"\t${3:operator}(() => ${4:EMPTY})",
511+
"\t)",
512+
");"
513+
]
514+
},
515+
"NgRx Create Effect for API Call": {
516+
"prefix": "a-ngrx-create-effect-api",
517+
"description": "Creates an NgRx Effect Scaffolded for API Call",
518+
"body": [
519+
"${1:effectName}$ = createEffect(() => this.actions$.pipe(",
520+
"\tofType(${2:Feature}Actions.${3:action}.type),",
521+
"\t${4:operator}(() =>",
522+
"\t\t${5:apiSource}.pipe(",
523+
"\t\t\tmap(data => $2Actions.$3Success({ data })),",
524+
"\t\t\tcatchError(error => of($2Actions.$3Failure({ error }))))",
525+
"\t\t)",
526+
"\t)",
527+
");"
528+
]
529+
},
530+
"NgRx Create Selector": {
531+
"prefix": "a-ngrx-create-selector",
532+
"description": "Creates an NgRx Selector",
533+
"body": [
534+
"export const select${1:Feature}${2:Property} = createSelector(",
535+
"\tselect$1,",
536+
"\t(state: $1State) => state.${3:property}",
537+
");"
538+
]
539+
},
540+
"NgRx Create Selector w/ Props": {
541+
"prefix": "a-ngrx-create-selector-props",
542+
"description": "Creates an NgRx Selector using props",
543+
"body": [
544+
"export const select${1:Feature}${2:Property} = createSelector(",
545+
"\tselect$1,",
546+
"\t(state: $1State, props) => ${3:selectLogic}",
547+
");"
460548
]
461549
},
550+
"NgRx Data Import Entity Data Module": {
551+
"prefix": "a-ngrx-data-entity-data-module-import",
552+
"description": "Import NgRx Entity Data Module",
553+
"body": ["EntityDataModule.forRoot(${1:entityConfig})"]
554+
},
462555
"NgRx Data Entity Metadata": {
463556
"prefix": "a-ngrx-data-entity-metadata",
464557
"description": "NgRx Data Entity Metadata",
465558
"body": [
466-
"import { EntityMetadataMap } from 'ngrx-data';",
559+
"import { EntityMetadataMap } from '@ngrx/data';",
467560
"",
468561
"const entityMetadata: EntityMetadataMap = {",
469562
" ${1:Model1}: {},${0}",
@@ -482,7 +575,7 @@
482575
"import {",
483576
" EntityCollectionServiceBase,",
484577
" EntityCollectionServiceElementsFactory",
485-
"} from 'ngrx-data';",
578+
"} from '@ngrx/data';",
486579
"import { ${1:Model} } from '${2:../core}';",
487580
"",
488581
"@Injectable({ providedIn: 'root' })",
@@ -492,21 +585,5 @@
492585
" }",
493586
"}"
494587
]
495-
},
496-
"Angular Resolver": {
497-
"prefix": "a-resolver",
498-
"description": "Angular Resolver",
499-
"body": [
500-
"import { Injectable } from '@angular/core';",
501-
"import { Resolve, ActivatedRouteSnapshot } from '@angular/router';",
502-
"import { Observable } from 'rxjs';",
503-
"",
504-
"@Injectable({ providedIn: 'root' })",
505-
"export class ${1:YourResolver} implements Resolve<${2:ObjectToResolve}> {",
506-
"\tresolve(route: ActivatedRouteSnapshot): Observable<${2:ObjectToResolve}> | Promise<${2:ObjectToResolve}> | ${2:ObjectToResolve} {",
507-
"\t\treturn ${0};",
508-
"\t}",
509-
"}"
510-
]
511588
}
512589
}

0 commit comments

Comments
 (0)