Skip to content

Convert template.js to a class #2147

@lhw-1

Description

@lhw-1

Please confirm that you have searched existing issues in the repo

Yes, I have searched the existing issues

Any related issues?

#2143

What is the area that this feature belongs to?

Code Quality

Is your feature request related to a problem? Please describe.

Currently, packages/core/template/template.js exports a function Template, which is then used in packages/core/src/Site/index.js to start the initialization process when markbind init is called in the CLI.

However, the way the code is currently structured could be improved by converting the Template function into a class instead, which would allow us to have the init method be part of the Template class rather than have it be declared as Template.prototype.init() as it currently is being done.

This also simplifies the current migration process for template.js into TypeScript in #2143.

As a reference, the Template function was never a class to begin with, and was introduced in this commit as part of #935, meaning that there was never an issue where we had to convert it from a class to a function.

Describe the solution you'd like

Convert the current Template function into a class, which would not change the way it is currently being called.

Currently, there is a prototype.init function that implements the Template function, which causes the calling statement to be:

return await new Template(rootPath, templatePath).init();

as seen here.

If the Template function is instead converted to a class (and the init function into a method of the class), then the way it is called will not change, meaning that it should not cause external issues - it will only affect how the code is organized within template.js. Moreover, this exact Template function is only used within packages/core/src/Site/index.js and nowhere else in the codebase currently, and so there should not be any unintended effects.

Regardless, any review would be welcome so as to make sure that the change is standalone and doesn't result in unintended consequences!

An example of what the conversion would look like can be seen in the PR addressing this issue: #2148.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions