stacks-schematics v1.1.4
Stacks Schematics
This library is only useful when you use NX monorepo.
It is also tailored for my specific needs. Although I can imagine it can be useful for someone else. Therefor I've published it on npm.
At the moment of release it only contains a useful schema when you use ngrx in the nx monorepo.
The Stacks Schematics contain:
- new-store
new-store
the new-store schema an addition on creating a new store with ngrx. It wil create CRUD ready ngrx store files.
How to use
First create a new library for your new feature store. Use the feature name in plural form, for example product becomes products So let us use products as example:
ng g @nrwl/angular:lib data-access/product
then create the ngrx feature store:
ng g @nrwl/angular:ngrx products --module=libs/data-access/products/src/lib/products.module.ts --directory +state/products --facade
We then replace the files that are created with CRUD-ready files with the following command, here it is important to not use the plural form of the feature. So instead of products we use product for the name:
ng g stacks-schematics:new-store --name=product --project=data-access-products --force
It now will create the following files:
├── +state/
├── products.actions.ts
├── products.effects.ts
├── products.facade.ts
├── products.models.ts
├── products.reducer.ts
├── products.selectors.ts
├── shared/
├── products.service.ts
It is good to note that the service that is created looks as follows:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ProductDto } from '@stacks/shared/stacks-dto';
import {BaseApiService} from '@stacks/app/app-base';
@Injectable({
providedIn: 'root',
})
export class ProductService extends BaseApiService<ProductDto>{
constructor(public http: HttpClient) {
super(http, '/api/product');
}
}
This is because it is created for my specific needs. It will create nice files which speed up the creation of a new store. But if you want to use this, this will mean that you need to edit the files to your needs.