Skip to content

Commit

Permalink
Now adds AppStore when running initialize schematic and adds AppStore…
Browse files Browse the repository at this point in the history
… provider to AppModule
  • Loading branch information
egervari committed Oct 30, 2018
1 parent 2dff789 commit f6a4c44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/schematics/initialize/files/app.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { AppState } from '../types/app-state/app-state.interface';

@Injectable()
export class AppStore {
constructor(private store: Store<AppState>) {}

public getAppState(): Observable<AppState> {
return this.store.pipe(select(state => state));
}
}
14 changes: 14 additions & 0 deletions src/schematics/initialize/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { chain, schematic, Rule, Tree } from '@angular-devkit/schematics';

import { addProviderToNgModule } from '../../ast/ast-wrappers';
import { reworkAppReducer } from '../../ast/rework-app-reducer/rework-app-reducer';
import { modifySourceFile } from '../../rules/modify-source-file.rule';
import { processTemplates } from '../../rules/process-templates.rule';
import { updateBarrelFile } from '../../rules/update-barrel-file.rule';

const AppModule = 'src/app/app.module.ts';
Expand Down Expand Up @@ -73,6 +75,18 @@ export default function(): Rule {
);
}
},
processTemplates({
path: 'src/app/store'
}),
(tree: Tree) => {
if (tree.exists(AppModule)) {
return modifySourceFile(
() => AppModule,
(sourceFile, moduleFilename) =>
addProviderToNgModule(sourceFile, moduleFilename, 'AppStore', `./store/app.store`)
);
}
},
(tree: Tree) => {
if (tree.exists(AppReducer)) {
return modifySourceFile(() => AppReducer, sourceFile => reworkAppReducer(sourceFile));
Expand Down

0 comments on commit f6a4c44

Please sign in to comment.