Skip to content

Commit

Permalink
docs(global): 📝 write comment in code for better understanding
Browse files Browse the repository at this point in the history
write comment in code for better understanding

Ref #54
  • Loading branch information
PritamBag committed Jan 6, 2025
1 parent af5f7fa commit 77d98cd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
31 changes: 24 additions & 7 deletions app/factory/ToolBox.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import { PropertyToolBoxData } from "../components/data/toolbox/property/Propert
import { ThemeToolBoxData } from "../components/data/toolbox/ThemeToolBox.data";
import { ToolBoxData } from "../components/data/toolbox/ToolBox.data";

/**
* ToolboxFactory class provides methods to create different toolbox components based on the icon type.
* The factory pattern is used to abstract the instantiation of specific toolbox data.
*/
export default class ToolBoxFactory {

/**
* A constant object holding various toolbox names for different toolboxes available in the toolbox group.
* These variants correspond to specific toolbox actions or categories within the toolbox group.
*/
static VARIANTS = {
COMPONENT: "component",
DEVICE : "device",
Expand All @@ -17,26 +24,36 @@ export default class ToolBoxFactory {
PROPERTY : "property",
THEME : "theme",
} as const;

/**
* Factory method to create and return the appropriate toolbox data based on the provided toolbox variant.
* This method abstracts the creation logic and returns instances of the corresponding toolbox data class.
*
* @param toolboxVariant - The type of toolbox (e.g., "component", "device", "layout").
* @returns A new instance of the appropriate ToolBoxData subclass based on the toolboxVariant.
* @throws Error if the provided toolboxVariant is not recognized.
*/
static getToolBoxData<T extends ToolBoxData>(toolboxVariant: string) :T {
switch (toolboxVariant) {
case ToolBoxFactory.VARIANTS.PROPERTY:
return new PropertyToolBoxData() as T;
return new PropertyToolBoxData() as T; // Return a new instance of PropertyToolBoxData when the toolboxVariant is "property".

case ToolBoxFactory.VARIANTS.DEVICE:
return new DeviceToolBoxData() as T;
return new DeviceToolBoxData() as T; // Return a new instance of DeviceToolBoxData when the toolboxVariant is "device".

case ToolBoxFactory.VARIANTS.LAYOUT:
return new LayoutToolBoxData() as T;
return new LayoutToolBoxData() as T; // Return a new instance of LayoutToolBoxData when the toolboxVariant is "layout".

case ToolBoxFactory.VARIANTS.COMPONENT:
return new ComponentToolBoxData() as T;
return new ComponentToolBoxData() as T; // Return a new instance of LayoutToolBoxData when the toolboxVariant is "component".

case ToolBoxFactory.VARIANTS.THEME:
return new ThemeToolBoxData() as T;
return new ThemeToolBoxData() as T; // Return a new instance of LayoutToolBoxData when the toolboxVariant is "theme".

case ToolBoxFactory.VARIANTS.NAVIGATOR:
return new NavigatorToolBoxData() as T;
return new NavigatorToolBoxData() as T; // Return a new instance of LayoutToolBoxData when the toolboxVariant is "navigator".

// If the toolboxVariant doesn't match any of the defined variants, throw an error.
default:
throw new Error(`Unknown entity type: ${toolboxVariant}`);
}
Expand Down
23 changes: 20 additions & 3 deletions app/factory/Toolbar.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,44 @@ import { RequestForReviewToolData } from "../components/data/toolbar/RequestForR
import { SaveToolData } from "../components/data/toolbar/SaveTool.data";
import { ToolbarData } from "../components/data/toolbar/Toolbar.data";

/**
* ToolbarFactory class provides methods to create different toolbar components based on the icon type.
* The factory pattern is used to abstract the instantiation of specific toolbar data.
*/
export default class ToolbarFactory {
/**
* A constant object holding various icon names for different tools available in the toolbar.
* These icons correspond to specific tool actions within the toolbar.
*/
static ICONS = {
HISTORY : "history",
REQUEST_FOR_REVIEW: "rate_review",
SAVE : "save",
} as const;

/**
* Factory method to get the appropriate viewer data based on the provided tool icon.
* This method creates a new instance of a specific toolbar tool data class based on the icon name.
*
* @param toolsIcon - The icon name of the toolbar tool. It determines which tool data to return.
* @returns A new instance of the corresponding ToolbarData subclass.
* @throws Error if the provided icon is not recognized.
*/
static getViewerData<T extends ToolbarData>(toolsIcon: string) :T {
switch (toolsIcon) {
case ToolbarFactory.ICONS.HISTORY: {
return new HistoryToolData() as T;
return new HistoryToolData() as T; // Return a new instance of HistoryToolData for the "history" icon.
}

case ToolbarFactory.ICONS.REQUEST_FOR_REVIEW: {
return new RequestForReviewToolData() as T;
return new RequestForReviewToolData() as T; // Return a new instance of RequestForReviewToolData for the "rate_review" icon.
}

case ToolbarFactory.ICONS.SAVE: {
return new SaveToolData() as T;
return new SaveToolData() as T; // Return a new instance of SaveToolData for the "save" icon.
}

// If the provided icon is not recognized, throw an error.
default: {
throw new Error(`Unknown entity type: ${toolsIcon}`);
}
Expand Down
22 changes: 20 additions & 2 deletions app/factory/Viewer.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@ import { JsonViewerData } from "../components/data/viewer/json/JsonViewer.data";
import { ModelViewerData } from "../components/data/viewer/model/ModelViewer.data";
import { ViewerData } from "../components/data/viewer/Viewer.data";

/**
* ViewerFactory class provides methods to create different viewer components based on the variant type.
* The factory pattern is used to abstract the instantiation of specific variant data.
*/
export default class ViewerFactory {
/**
* A constant object holding various variant names for different variants available in the viewer group.
* These variants correspond to specific actions or types within the viewer group.
*/
static VARIANTS = {
JSON : "JSON",
MODEL: "Model"
} as const;

/**
* Factory method to create and return a viewer data instance based on the provided viewer type (variant) and entity data.
* This method abstracts the creation of different viewer data classes based on the variant type.
*
* @param viewerTab - The type of viewer (e.g., "JSON", "Model").
* @param entityData - The dynamic entity data that will be passed to the viewer data classes.
* @returns A new instance of the appropriate ViewerData subclass based on the viewerTab.
* @throws Error if the provided viewerTab is not recognized.
*/
static getViewerData<T extends ViewerData>(viewerTab: string, entityData: DynamicEntity) :T {
switch (viewerTab) {

case ViewerFactory.VARIANTS.JSON:
return new JsonViewerData(entityData) as T;
return new JsonViewerData(entityData) as T; // Return a new instance of JsonViewerData when the viewerTab is "JSON".

case ViewerFactory.VARIANTS.MODEL:
return new ModelViewerData(entityData) as T;
return new ModelViewerData(entityData) as T; // Return a new instance of ModelViewerData when the viewerTab is "Model".

// If the viewerTab doesn't match any of the defined variants, throw an error.
default:
throw new Error(`Unknown viewer type: ${viewerTab}`);
}
Expand Down

0 comments on commit 77d98cd

Please sign in to comment.