Skip to content

Change Frontend Responses to use Classes #399

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

Closed
mfish33 opened this issue Dec 6, 2021 · 0 comments · Fixed by #394
Closed

Change Frontend Responses to use Classes #399

mfish33 opened this issue Dec 6, 2021 · 0 comments · Fixed by #394
Assignees
Labels
Web Involves web programming (TypeScript, Svelte, CSS)
Milestone

Comments

@mfish33
Copy link
Contributor

mfish33 commented Dec 6, 2021

Currently, the frontend uses a reactive system to alert different parts of the frontend about editor changes. In order to do this, all responses are described by interfaces and have a corresponding new function.

export interface SaveDocument {
	document: string;
	name: string;
}
function newSaveDocument(input: any): SaveDocument {
	return {
		document: input.document,
		name: input.name,
	};
}

Switching to a class-based system would have various benefits

  • Classes stay in after compilation. This would allow us to offer better type checking on the main subscription API
function registerResponseHandler(responseType: ResponseType, callback: ResponseCallback)

to

function subscribeJsMessage<T extends JsMessage>(responseType: Constructs<T>, callback: JsMessageCallback<T>)

The advantage of this change is that the callback given to subscribeJsMessage automatically has the correct type for the input parameter and does not need to be cast. Removing this cuts down on boilerplate code where mistakes can be made.

  • The other advantage of a class-based system is we can remove the new function to create a given type. Instead, we can make use of a library class-transformer in order to automate this process, further cutting down on code duplication.

  • Finally while implementing the class solution, naming should be refactored to better align with the backend message system

@mfish33 mfish33 added Cleanup Web Involves web programming (TypeScript, Svelte, CSS) labels Dec 6, 2021
@mfish33 mfish33 added this to the Sprint 9 (ongoing) milestone Dec 6, 2021
@mfish33 mfish33 self-assigned this Dec 6, 2021
@mfish33 mfish33 linked a pull request Dec 6, 2021 that will close this issue
@Keavon Keavon added the P-Medium label Dec 6, 2021
@0HyperCube 0HyperCube moved this to Completed This Sprint in Task Board Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Web Involves web programming (TypeScript, Svelte, CSS)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants