Skip to content

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

@hemangsk

Description

@hemangsk

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions