2
votes

I saw we can customize our actions in ngrx/data like below

https://ngrx.io/guide/data/entity-actions#tagging-the-entityaction

enter image description here

Therefore, my question is how could I create these customized actions in the normal ***.actions.ts files (example)

import { createAction, props } from '@ngrx/store';

export const normalFooAction = createAction(
  ‘[Foo] foo’,
  props<{ foo: string }>()
);

¿¿¿
    export const customizedNRGXDataAction = createAction(
    ———
    this.entityActionFactory.create<Hero>(
      'Hero',
      EntityOp.QUERY_ALL,
      null,
      { tag: 'Load Heroes On Start' }
    );
    ———
???

through entityActionFactory as I wrote before to then use it in a effect? (example)

    @Injectable()
        export class FooEffects {
         ***
¿¿¿
          loadCustomizedNRGXDataAction$ = createEffect(() => this.actions$.pipe(
            ofType(FooActions.customizedNGRXDataAction),
???
           ***
             ))
            )
          );

Is that possible?

Many thanks in advance

1

1 Answers

0
votes

You can create it as an object in your store and then provide into your module via useValue to share it with modularized services.

export const myEntityActionFactory = new EntityActionFactory();
// to avoid duplicates you need to assign it to window.myEntityActionFactory and create a getter function.

// use it somewhere.
@NgModule({
  imports: [
    EntityDataModule.forRoot(...),
  ],
  provides: [
    {
      provide: EntityActionFactory,
      useValue: myEntityActionFactory,
    },
  ],
})