Would you consider having the actions expressed in classes same as in the example app?
I changed it for my local copy as I prefer to have the type checking available for action names.
Doesn't look complicated and works with the persistence class as well.
For example here my actions template.
import { Action } from "@ngrx/store";
export const LOAD_DATA = 'LOAD_DATA';
export const DATA_LOADED = 'DATA_LOADED';
export class LoadData implements Action {
readonly type = LOAD_DATA;
constructor(public payload: {}) {}
}
export class DataLoaded implements Action {
readonly type = DATA_LOADED;
constructor(public payload: {}) {}
}
export type <%= className %>Action = LoadData | DataLoaded;
I am not a fan of using classes for that. It seems unnecessary verbose, and makes actions not truly serializable. But I'm thinking about using an enum for action names: https://github.com/nrwl/nx/issues/78
I agree with this request. I think it is shortsighted not to use Action classes. The very reason why the Action class dropped the payload attribute is because it wasn't typesafe and didn't encourage people to write typesafe code.
We use nx-workspace (and we like it a lot), but this issue here is our one big problem with it. We are considering writing a different ngrx generator just because of this.
At the very least, you could add it as a separate parameter for the schematic as to which style you prefer.
@vsavkin - I suggest that this be reopened and perhaps associated with #174
Most helpful comment
I agree with this request. I think it is shortsighted not to use Action classes. The very reason why the Action class dropped the payload attribute is because it wasn't typesafe and didn't encourage people to write typesafe code.
We use nx-workspace (and we like it a lot), but this issue here is our one big problem with it. We are considering writing a different ngrx generator just because of this.
At the very least, you could add it as a separate parameter for the schematic as to which style you prefer.