Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationships constants in generators #26075

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

Tcharl
Copy link
Contributor

@Tcharl Tcharl commented May 8, 2024

The goal being to be able to find in one click within an IDE all the relationship usage within the entire jhipster codebase.

Do you agree with the design? Is so, I'll continue on the entire codebase


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (below reviewers) and adding skip-ci label, you can still see CI build result at your branch.

generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
@mshima
Copy link
Member

mshima commented May 8, 2024

Many generators are written in typescript now.
In my opinion using variables now is not as useful as it was before.
It creates too much overhead.

import { fooType } from '../../jdl/jhipster/index.js';

const { A_CONSTANT } = fooType;

value === A_CONSTANT;

Instead of:

value === 'aConstant'; // validated by typescript (undefined | 'aConstant' | 'anotherConstant')

@Tcharl
Copy link
Contributor Author

Tcharl commented May 8, 2024

Agreed that it needs more lines, still, using constants instead of plain strings permits:

  • Folding in IDE ('find usage'), which helps newcomers to better understand the codebase
  • Prevents Typo
  • Ease the migration to proper typescript (constant will be an enum of the class)
  • Ensures proper modules acyclic graph (because we're referencing a constant that is in a 'support' package of another module)
  • Ensures type safety on methods signatures
  • Allows loops over constants of the consts record
  • And for sure a bit more (I hope that typescript will soon implements sealed class like java does)

So IMHO, the benefits overcomes the drawbacks.

@Tcharl Tcharl changed the title proof of concept regarding relationships constants in generator Relationships constants in generators May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants