-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3d692c
commit 4e340cc
Showing
12 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/collection/ngrx/creator-files/__directory__/__fileName__.actions.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export enum Types {} | ||
|
||
export type CollectiveType = Action; |
27 changes: 27 additions & 0 deletions
27
src/collection/ngrx/creator-files/__directory__/__fileName__.effects.spec.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Observable } from 'rxjs'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { provideMockStore } from '@ngrx/store/testing'; | ||
import { NxModule } from '@nrwl/angular'; | ||
import { cold, hot } from 'jest-marbles'; | ||
import { <%= className %>Effects } from './<%= fileName %>.effects'; | ||
|
||
describe('<%= className %>Effects', () => { | ||
let actions: Observable<any>; | ||
let effects: <%= className %>Effects; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NxModule.forRoot() | ||
], | ||
providers: [ | ||
<%= className %>Effects, | ||
provideMockActions(() => actions), | ||
provideMockStore({ initialState: {} }), | ||
], | ||
}); | ||
|
||
effects = TestBed.inject(<%= className %>Effects); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
src/collection/ngrx/creator-files/__directory__/__fileName__.effects.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Effect } from '@ngrx/effects'; | ||
import * as from<%= className %>Actions from './<%= fileName %>.actions'; | ||
import { <%= className %>PartialState } from './<%= fileName %>.reducer'; | ||
import { Actions } from '@ngrx/store'; | ||
|
||
@Injectable() | ||
export class <%= className %>Effects { | ||
constructor(private actions$: Actions) {} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/collection/ngrx/creator-files/__directory__/__fileName__.facade.spec.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Store } from '@ngrx/store'; | ||
import { MockStore, provideMockStore } from '@ngrx/store/testing'; | ||
import { NxModule } from '@nrwl/angular'; | ||
import { Observable } from 'rxjs'; | ||
import { <%= className %>Facade } from './<%= fileName %>.facade'; | ||
|
||
describe('<%= className %>Facade', () => { | ||
let actions: Observable<any>; | ||
let facade: <%= className %>Facade; | ||
let store: MockStore; | ||
|
||
describe('used in NgModule', () => { | ||
|
||
beforeEach(() => { | ||
@NgModule({ | ||
imports: [], | ||
providers: [ | ||
<%= className %>Facade, | ||
provideMockStore(), | ||
provideMockActions(() => actions) | ||
] | ||
}) | ||
class CustomFeatureModule {} | ||
|
||
@NgModule({ | ||
imports: [ | ||
NxModule.forRoot(), | ||
CustomFeatureModule, | ||
] | ||
}) | ||
class RootModule {} | ||
|
||
TestBed.configureTestingModule({ imports: [RootModule] }); | ||
facade = TestBed.inject(<%= className %>Facade); | ||
store = TestBed.inject(MockStore); | ||
jest.spyOn(store, 'dispatch'); | ||
}); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
src/collection/ngrx/creator-files/__directory__/__fileName__.facade.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { select, Store } from '@ngrx/store'; | ||
import { <%= className %>PartialState } from './<%= fileName %>.reducer'; | ||
import { <%= propertyName %>Query } from './<%= fileName %>.selectors'; | ||
|
||
@Injectable() | ||
export class <%= className %>Facade { | ||
constructor(private store: Store<<%= className %>PartialState>) {} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/collection/ngrx/creator-files/__directory__/__fileName__.reducer.spec.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as from<%= className %>Actions from './<%= fileName %>.actions'; | ||
import { <%= className %>State, initialState, reducer } from './<%= fileName %>.reducer'; | ||
|
||
describe('<%= className %> Reducer', () => { | ||
let state: <%= className %>State; | ||
|
||
beforeEach(() => { | ||
state = { ...initialState }; | ||
}); | ||
|
||
describe('unknown action', () => { | ||
test('returns the initial state', () => { | ||
const action = {} as any; | ||
const result = reducer(state, action); | ||
|
||
expect(result).toBe(state); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/collection/ngrx/creator-files/__directory__/__fileName__.reducer.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as from<%= className %>Actions from './<%= fileName %>.actions'; | ||
import { createReducer, ActionReducer } from '@ngrx/store'; | ||
|
||
export const <%= className.toUpperCase() %>_FEATURE_KEY = '<%= propertyName %>'; | ||
|
||
export interface <%= className %>State { | ||
}; | ||
|
||
export interface <%= className %>PartialState { | ||
readonly [<%= className.toUpperCase() %>_FEATURE_KEY]: <%= className %>State; | ||
} | ||
|
||
export const initialState: <%= className %>State = {}; | ||
|
||
const <%= propertyName %>Reducer = createReducer(initialState); | ||
|
||
export function reducer( | ||
state: <%= className %>State = initialState, | ||
action: from<%= className %>Actions.CollectiveType | ||
): ActionReducer<<%= className %>State, from<%= className %>Actions.CollectiveType> { | ||
return <%= propertyName %>Reducer(state, action); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/collection/ngrx/creator-files/__directory__/__fileName__.selectors.spec.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { initialState, <%= className.toUpperCase() %>_FEATURE_KEY, <%= className %>State } from './<%= fileName %>.reducer'; | ||
import { <%= propertyName %>Query } from './<%= fileName %>.selectors'; | ||
|
||
describe('<%= className %> Selectors', () => { | ||
let storeState: { [<%= className.toUpperCase() %>_FEATURE_KEY]: <%= className %>State }; | ||
|
||
beforeEach(() => { | ||
storeState = { | ||
[<%= className.toUpperCase() %>_FEATURE_KEY]: initialState | ||
}; | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/collection/ngrx/creator-files/__directory__/__fileName__.selectors.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createFeatureSelector, createSelector } from '@ngrx/store'; | ||
import { <%= className.toUpperCase() %>_FEATURE_KEY, <%= className %>State } from './<%= fileName %>.reducer'; | ||
|
||
// Lookup the '<%= className %>' feature state managed by NgRx | ||
const get<%= className %>State = createFeatureSelector<<%= className %>State>(<%= propertyName.toUpperCase() %>_FEATURE_KEY); | ||
|
||
export const <%= propertyName %>Query = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters