Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@ngrx/schematics] Optionally generate entity pattern (introduce -e / --entity flag) when generating NgRx feature #3260

Closed
tomastrajan opened this issue Dec 5, 2021 · 1 comment · Fixed by #3850

Comments

@tomastrajan
Copy link

Currently the ng g feature path/to/feature/state/<state-name> -a -c --module path/to/feature is great to scaffold whole state features in the consistent fashion across many features / projects.

The issue is that when used, the generated reducer is "vanilla" eg not implementing entity pattern.

It would be great to introduce additional -e or --entity flag which would

  • generate reducer with all the boilerplate for entity pattern in place
  • generate .model.ts with stub interface (same as for ng g entity)
  • adjust generated on(...) handlers to already use adapter as it can be expected that genrated load (and success) action will lead to ...adapter.setAll(<entity name>, state) implementation in loadSuccess handler.

Describe any alternatives/workarounds you're currently using

The entity pattern needs to be added manually into the generated reducer (or the entity reducer generated over the previously generated state feature)

Other information:

Would be great as the ng g feature ... already is doing soo much good in terms of consistency of projects!

If accepted, I would be willing to submit a PR for this feature

[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ x] No (sorry, extremely busy lately 😅)

@wgd3
Copy link
Contributor

wgd3 commented Apr 5, 2023

@brandonroberts I'd love to try tackling this! I'm working on a branch here: https://github.com/wgd3/platform/tree/issue-3260

Before I open a PR, I have one question - should this functionality support an entity with a name that's different from the feature name? Or just create an entity with the feature name, and let the user run ng g entity afterwards? I could see something like "I want a feature ToDoList with one entity named ToDo and another entity named Category"

wgd3 pushed a commit to wgd3/platform that referenced this issue Apr 17, 2023
BEFORE:

Entity schematic had to be run after generating a new feature:

```sh
ng generate feature User

ng generate entity User -m app.module.ts -r user.reducer.ts
```

AFTER:

Feature schematic allows for creation of an entity:

```sh
ng generate feature User --entity
```

closes ngrx#3260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants