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

Rewrite the whole lib with TypeScript & ES6 Class instead of Function prototype for easier to maintain and expand #20

Closed
cnwangjie opened this issue Jul 16, 2024 · 4 comments

Comments

@cnwangjie
Copy link

cnwangjie commented Jul 16, 2024

Description

This issue proposes a significant refactor of the library, transitioning from the current function prototype-based approach to a modern TypeScript and ES6 class-based architecture. The primary motivation behind this change is to improve the library's maintainability, scalability, and overall developer experience.

Current Problems

Inherent Limitations of Prototypal Inheritance: The current function prototype inheritance model can become complex and cumbersome, especially as the codebase grows and new features are added. It often leads to deeply nested object structures and a less intuitive understanding of the code.
Lack of Static Typing (JavaScript): Without static typing, we rely on runtime checks to catch errors, which can lead to unexpected issues in production. TypeScript's static type system would help prevent these problems at compile time.
Readability and Maintainability Concerns: The prototype-based code can be less readable and harder to reason about than the structured class approach, potentially hindering future development and maintenance efforts.

Proposed Solution

  • TypeScript Adoption: We will migrate the entire codebase to TypeScript. This will introduce static typing, enabling us to catch errors early, improve code quality, and enhance developer productivity through code autocompletion and better tooling.

  • ES6 Class Conversion: We will refactor all existing functions and prototype-based objects into ES6 classes. This change will provide a more organized and structured approach to code organization, making the codebase easier to understand, maintain, and extend.

  • Modular Code Structure: Currently, a lot of code is written based on ES5. It's worth writing with ES6 syntax to aid understanding and maintenance.

@cnwangjie
Copy link
Author

I am working on creating some products around ComfyUI. I have already implemented many parts of it in my code using TypeScript. I'd like to contribute to this project. If no other one is working or has a plan to do this.

@DrJKL
Copy link

DrJKL commented Aug 2, 2024

@cnwangjie There's a parallel effort to do just this.

@jagenjo
Copy link
Contributor

jagenjo commented Aug 6, 2024

I second this (and Im the culprit of most of it).

@webfiltered
Copy link
Collaborator

There are some stragglers, but this is now done.

Some sections were intentionally ignored because they're unused, have not been maintained, and are likely targets for pruning. There are also more expect-error directives than I'd like, but the vast majority are in or related to the same ignored sections.

Whilst there's clean up to do in many places, and rewrites in others, all the boxes are finally ticked for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants