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]
2525
2626Provide the path to your file with an exported state interface
2727
28- - ` --reducers `
28+ - ` --state `
2929 - Type: ` string `
3030
3131Provide 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
3939Generate a ` UsersPage ` container component with your reducers imported and the ` Store ` typed a custom interface named ` MyState ` .
4040
4141``` sh
42- ng generate container UsersPage --reducers reducers/index.ts --stateInterface MyState
42+ ng generate container UsersPage --state reducers/index.ts --stateInterface MyState
4343```
Original file line number Diff line number Diff line change @@ -46,6 +46,15 @@ describe('Container Schematic', () => {
4646 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 ' ; / ) ;
4747 } ) ;
4848
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+
4958 it ( 'should update the component constructor if the state path if provided' , ( ) => {
5059 const options = { ...defaultOptions , state : 'reducers' } ;
5160 appTree . create ( '/src/app/reducers' , '' ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,12 @@ function addStateToComponent(options: FeatureOptions) {
6161 ) ;
6262
6363 const stateImportPath = buildRelativePath ( componentPath , statePath ) ;
64+ const storeImport = insertImport (
65+ source ,
66+ componentPath ,
67+ 'Store' ,
68+ '@ngrx/store'
69+ ) ;
6470 const stateImport = options . state
6571 ? insertImport (
6672 source ,
@@ -94,7 +100,7 @@ function addStateToComponent(options: FeatureOptions) {
94100 `\n\n ${ storeConstructor } `
95101 ) ;
96102
97- const changes = [ stateImport , constructorUpdate ] ;
103+ const changes = [ storeImport , stateImport , constructorUpdate ] ;
98104 const recorder = host . beginUpdate ( componentPath ) ;
99105
100106 for ( const change of changes ) {
You can’t perform that action at this time.
0 commit comments