Closed lusloher closed 3 years ago
You should not pluralize a union type like that.
A reducer expects a flow action, this can be read as "action of type FlowAction".
If you pluralize ImportFlowAction
as Type FlowActionTypes
but it's just one action and therefore of type FlowAction
.
Another really simple example: No one would consider pluralizing booleans, even though there are two values, that are of type Boolean.
Apart from that: You should use the following pattern here.
const flowActions = ['CreateFlowAction', 'LoadFlowAction', ... ] as const
You assert as const, to prevent type widening to string[]
To turn it into a union type, like the one above can now be done by just doing
type FlowAction = typeof flowActions[number]
To clarify things: There are some actual problems, that can be caused by naming types that way. But in the long run, renaming the Types doesn't matter as much. Leaving behind the mental model, that is related to that naming pattern, will be more relevant for advancing the codebase.
I encountered the exact same issue with NGRX - too much repetetive boilerplate code for actions as well as for reducers.
you can generate classes named dynamically like this:
`const ClassFactory = (className) => { const obj = {}; obj[className] = class { }; return obj[className]; };
const classA = ClassFactory('classA');`
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days
@BastinJafari @Roshanjossey has this progressed any further than the above discussion?
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days
We're moving away from Redux.
Maintenance
Right now you have to write down the action types manually like
`export type FlowActionTypes =
| LoadFlowAction
| CreateNewFlowAction
| UpdateFlowChartAction
| UpdateSelectedFlowAction
| DuplicateFlowAction
| DeleteFlowAction
| UpdateNodeAction
| DeleteNodeAction
| RerenderAction
| ImportFlowAction
| SetFlowArgumentsAction`
It would be nice to generate this type dynamically out of an object or a list.
Acceptance Criteria
Good community issue
┆Issue is synchronized with this Asana task by Unito