This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Fe guidelines standarts constants utils #91
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33e3371
refs #644619 fix note
fa60771
refs #644619 constants
4fd8fd1
refs #644619 utils
8855164
refs #644619 links to constants and utils
e8f3ada
refs #644619 remove highlighted of best practices
25f99e2
refs #644619 add info about index.ts for constants
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
docs/Frontend_tutorials/standards/FE-Standards-constants.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Frontend Constants Guidelines | ||
|
|
||
| This section provides conventions and examples for defining and using constants in the frontend codebase. Constants improve readability, maintainability, and help eliminate magic numbers or strings scattered throughout the code. | ||
|
|
||
| --- | ||
|
|
||
| ## Example: Message Constants and UI Offsets | ||
|
|
||
| ```ts | ||
| import { EasyAIMessage, MessageOriginType, StreamMessageType } from "../types/message"; | ||
|
|
||
| export const EMPTY_STREAM_AI_MESSAGE: Readonly<EasyAIMessage> = { | ||
| origin: MessageOriginType.Stream, | ||
| message: "", | ||
| type: StreamMessageType.Message, | ||
| }; | ||
|
|
||
| export const ACTIVATOR_POSITION_OFFSET_TOP_PX = 25; | ||
| export const ACTIVATOR_POSITION_OFFSET_LEFT_PX = 5; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Usage Example | ||
|
|
||
| ```ts | ||
| import { EMPTY_STREAM_AI_MESSAGE } from "@/src/shared/constants/messages"; | ||
|
|
||
| function createInitialMessage() { | ||
| return { ...EMPTY_STREAM_AI_MESSAGE }; // Safe to copy, can't be mutated | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Best Practices | ||
|
|
||
| - Group constants by purpose into logically named files (e.g., `constants/ui.ts`, `constants/messages.ts`). | ||
| - Use explicit type annotations for structured or domain-specific constants. | ||
| - Write descriptive names that clarify intent and usage. | ||
| - Use `export const` to guarantee immutability. | ||
| - Use `UPPER_SNAKE_CASE` for all constant names. | ||
| - Include unit suffixes in names when applicable (e.g., `_PX`, `_MS`, `_CHARS`) to clarify what the value represents. | ||
| - Use `Readonly<Type>` for object constants to prevent accidental mutation. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Frontend Utils Guidelines | ||
|
|
||
| This section outlines best practices for creating and maintaining helper functions within the `utils/` folder. These functions provide reusable logic that is not specific to Vue or reactive state—typically dealing with DOM interactions, string/array manipulations, layout adjustments, or other side-effect–free helpers. | ||
|
|
||
| --- | ||
|
|
||
| ## Example: Layout Scrollbar Visibility | ||
|
|
||
| ```ts | ||
| import { NO_SCROLLBARS_CLASS } from "@/src/shared/constants/layout"; | ||
|
|
||
| export const setLayoutScrollbarsVisibility = (scrollbarsVisible: boolean): void => { | ||
| document.body.classList.toggle(NO_SCROLLBARS_CLASS, !scrollbarsVisible); | ||
| }; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Usage Example | ||
|
|
||
| ```ts | ||
| import { setLayoutScrollbarsVisibility } from "@/src/shared/utils/layout"; | ||
|
|
||
| setLayoutScrollbarsVisibility(false); | ||
|
|
||
| setLayoutScrollbarsVisibility(true); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
|
|
||
| ## Best Practices | ||
|
|
||
| - Place generic, reusable, non-Vue logic in the `utils/` folder. (Vue-specific logic should be in `composables/`.) | ||
| - Organize files by purpose (e.g., `utils/layout.ts`, `utils/string.ts`, `utils/dom.ts`). | ||
| - Prefer named exports for each utility function. | ||
| - Keep functions small, focused, and easy to test. | ||
| - Use descriptive names that reflect the function’s purpose (e.g., `setLayoutScrollbarsVisibility` instead of `toggleScrollbars`). | ||
| - Fully type all function parameters and return values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pouzivame jeste index.ts pro shared constant mozna taky dobre zminit nebo na uvahu na tebe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zminil jsem to tam: If a module has only a few constants (1-4), it is allowed to use an
index.tsfile in theconstantsfolder for simplicity.