jina-ai / dashboard

Interactive UI for analyzing Jina logs, designing Flows and viewing Hub images
https://dashboard.jina.ai
Apache License 2.0
118 stars 61 forks source link

Generate ActionTypes dynamically #244

Closed lusloher closed 3 years ago

lusloher commented 3 years ago

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

lusloher commented 3 years ago

Link to feature: https://jinaai.productboard.com/feature-board/planning/features/7073106

DavidSanwald commented 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]

DavidSanwald commented 3 years ago

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.

AvTe commented 3 years ago

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');`

jina-bot commented 3 years ago

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

aga11313 commented 3 years ago

@BastinJafari @Roshanjossey has this progressed any further than the above discussion?

jina-bot commented 3 years ago

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

jina-bot commented 3 years ago

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

Roshanjossey commented 3 years ago

We're moving away from Redux.