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

[schematics/feature] Prefix option is not used when generating effects and reducers #3116

Closed
hemangsk opened this issue Aug 15, 2021 · 1 comment · Fixed by #3139
Closed
Labels
Accepting PRs Good First Issue Good issue for first-time contributor Project: Schematics

Comments

@hemangsk
Copy link
Contributor

hemangsk commented Aug 15, 2021

This happens when we create a new Store for feature with the feature schematic.

The generation command:

ng generate feature dashboard/store/Dashboard -m dashboard/dashboard.module.ts --group  

with the following settings:

? Should we generate and wire success and failure actions? Yes
? Do you want to use the create functions? Yes
? What should be the prefix of the action? custom

This generates actions.ts with "custom prefix". But effects and reducers.ts still use the default "load" prefix. Related to (#3012)

Minimal reproduction of the bug/regression with instructions:

ng add @ngrx/schematics@latest  

ng g m dashboard --routing
ng g c dashboard/dashboard 

ng add @ngrx/store@latest

ng generate feature dashboard/store/Dashboard -m dashboard/dashboard.module.ts --group 

Expected behavior:

  • effects.ts and reducers.ts should use the supplied prefix.

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

  • "@ngrx/store": "^12.4.0"
  • "@angular/core": "~11.1.0"
  • "@angular/cli": "~11.1.0"
  • "@angular/compiler-cli": "~11.1.0"
  • "@ngrx/schematics": "^12.4.0"
  • node v14.15.2
  • Google Chrome Version 92.0.4515.131 (Official Build) (x86_64)

Other information:

I would be glad to submit a patch.
Possible solution:

function getEffectStart(name: string, creators?: boolean, prefix?: string): string {
  const effectName = stringUtils.classify(name);
  return creators
    ? `{prefix}${effectName}s$ = createEffect(() => {` +
        '\n    return this.actions$.pipe( \n'
    : '@Effect()\n' + `  load${effectName}s$ = this.actions$.pipe(`;
}

I would be willing to submit a PR to fix this issue

[x ] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@timdeschryver
Copy link
Member

I think that we can add this.
Feel free to create a PR with the changes @hemangsk

hemangsk added a commit to hemangsk/platform that referenced this issue Sep 5, 2021
Previously, passing --prefix when generating a feature would
make changes only in the generated action. This passes the prefix
option to the effect and reducers as well.

Fixes ngrx#3116
hemangsk added a commit to hemangsk/platform that referenced this issue Sep 5, 2021
Previously, passing --prefix when generating a feature would
make changes only in the generated action. This passes the prefix
option to the effect and reducers as well.

Fixes ngrx#3116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepting PRs Good First Issue Good issue for first-time contributor Project: Schematics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants