Skip to content

Commit

Permalink
Define APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tfukaza committed Jul 21, 2024
1 parent 43453e4 commit b2acddc
Show file tree
Hide file tree
Showing 10 changed files with 765 additions and 719 deletions.
30 changes: 30 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Folders and Files

- 📁 `components`: Code for SnapLine components, like nodes and lines.
- 📄`base.ts`: Defines the base component class.
- 📄`component.ts`: Defines the component class.
- 📄`connector.ts`: Defines the connector class.
- 📄`node.ts`: Defines the node class.
- 📁 `theme`: CSS for standard SnapLine themes.
- 📄`standard_dark.css`: Standard dark theme.
- 📄`standard_light.css`: Standard light theme.
- 📄 `camera.ts`: Code for the camera, which is used to move the view around.
- 📄 `helper.ts`: Helper functions.
- 📄 `index.ts`: The entry point for the SnapLine library.
- 📄 `input.ts`: Code for handling user input.

## Conventions

### Class Member Function Naming

There are three types of class member functions that exist in this library:

- Private: Functions that are not meant to be accessed outside of the _class_ nor the _library_. These functions are prefixed with a pound sign (`#`), which enforces privacy in JavaScript.
- Hidden: Functions that are only called within the _library_, but can be called between _classes_. These functions are prefixed with an underscore (`_`). Technically speaking, these functions are public, but they are not meant to be accessed outside of the _library_.
- Public: Functions that are meant to be accessed outside of the _library_. These functions are not prefixed with anything.

For private and hidden functions, the bundler will mangle (minify) the function names to reduce bundle size and discourage external code from directly calling these functions.

### Class Member Variable Naming

Similar to functions, there are three types of class member variables; private, hidden, and public. Their naming conventions are the same as functions. Also like functions, private and hidden variables will be mangled by the bundler.
12 changes: 6 additions & 6 deletions src/components/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export abstract class Base {
this.g.dx_offset = 0;
this.g.dy_offset = 0;

this.componentCursorDown(prop);
this._componentCursorDown(prop);
}

componentCursorDown(_: customCursorDownProp): void {
_componentCursorDown(_: customCursorDownProp): void {
console.debug(
`Base class componentCursorDown event triggered on ${this.gid} with prop ${JSON.stringify(_)}`,
);
Expand All @@ -96,10 +96,10 @@ export abstract class Base {
* Triggered when the dom of this object is released.
*/
domCursorUp(): void {
this.componentCursorUp();
this._componentCursorUp();
}

componentCursorUp(): void {
_componentCursorUp(): void {
// To be implemented by the child class
}

Expand All @@ -120,7 +120,7 @@ export abstract class Base {
/**
* Called for every frame when the object is being dragged.
*/
onDrag(): void {
_onDrag(): void {
// To be implemented by the child class
}

Expand All @@ -134,7 +134,7 @@ export abstract class Base {
/**
* Called when the object is being deleted.
*/
destroy(): void {
delete(): void {
// To be implemented by the child class
}
}
Loading

0 comments on commit b2acddc

Please sign in to comment.