File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
modules/schematics/src/container Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ ng generate co ComponentName [options]
25
25
26
26
Provide the path to your file with an exported state interface
27
27
28
- - ` --reducers `
28
+ - ` --state `
29
29
- Type: ` string `
30
30
31
31
Provide the name of the interface exported for your state interface
@@ -39,5 +39,5 @@ Provide the name of the interface exported for your state interface
39
39
Generate a ` UsersPage ` container component with your reducers imported and the ` Store ` typed a custom interface named ` MyState ` .
40
40
41
41
``` sh
42
- ng generate container UsersPage --reducers reducers/index.ts --stateInterface MyState
42
+ ng generate container UsersPage --state reducers/index.ts --stateInterface MyState
43
43
```
Original file line number Diff line number Diff line change @@ -46,6 +46,15 @@ describe('Container Schematic', () => {
46
46
expect ( content ) . toMatch ( / i m p o r t \* a s f r o m S t o r e f r o m ' ..\/ r e d u c e r s ' ; / ) ;
47
47
} ) ;
48
48
49
+ it ( 'should import Store into the component' , ( ) => {
50
+ const options = { ...defaultOptions , state : 'reducers' } ;
51
+ appTree . create ( '/src/app/reducers' , '' ) ;
52
+ const tree = schematicRunner . runSchematic ( 'container' , options , appTree ) ;
53
+ const content = getFileContent ( tree , '/src/app/foo/foo.component.ts' ) ;
54
+ console . log ( content ) ;
55
+ expect ( content ) . toMatch ( / i m p o r t \ { \ S t o r e \ } \ f r o m \ ' @ n g r x \/ s t o r e ' ; / ) ;
56
+ } ) ;
57
+
49
58
it ( 'should update the component constructor if the state path if provided' , ( ) => {
50
59
const options = { ...defaultOptions , state : 'reducers' } ;
51
60
appTree . create ( '/src/app/reducers' , '' ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,12 @@ function addStateToComponent(options: FeatureOptions) {
61
61
) ;
62
62
63
63
const stateImportPath = buildRelativePath ( componentPath , statePath ) ;
64
+ const storeImport = insertImport (
65
+ source ,
66
+ componentPath ,
67
+ 'Store' ,
68
+ '@ngrx/store'
69
+ ) ;
64
70
const stateImport = options . state
65
71
? insertImport (
66
72
source ,
@@ -94,7 +100,7 @@ function addStateToComponent(options: FeatureOptions) {
94
100
`\n\n ${ storeConstructor } `
95
101
) ;
96
102
97
- const changes = [ stateImport , constructorUpdate ] ;
103
+ const changes = [ storeImport , stateImport , constructorUpdate ] ;
98
104
const recorder = host . beginUpdate ( componentPath ) ;
99
105
100
106
for ( const change of changes ) {
You can’t perform that action at this time.
0 commit comments