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

Migration: Testing migration class to function component (Coordinates) #1516

Open
OlofSvahnVbg opened this issue May 24, 2024 · 2 comments
Open
Assignees
Labels
new feature Request for adding/changing functionality
Milestone

Comments

@OlofSvahnVbg
Copy link
Collaborator

The devs over at react seem to be recommending a migration from class to function components:

image

There are many pros to this and a pretty good and understandable list can be found here:
https://www.geeksforgeeks.org/why-it-is-recommended-to-use-functional-components-over-class-components/

That being said, it will certainly be difficult (and exhausting) to migrate every class component to functions in HAJK. Some class components are very long and contain logic that can be hard to keep track of, lifecycle methods for instance.

An idea is to use AI to some capacity for this. I don't know how, or which AI, but it might make this easier.

@OlofSvahnVbg OlofSvahnVbg added the new feature Request for adding/changing functionality label May 24, 2024
@OlofSvahnVbg OlofSvahnVbg added this to the 3.x milestone May 24, 2024
@OlofSvahnVbg OlofSvahnVbg self-assigned this May 24, 2024
@OlofSvahnVbg
Copy link
Collaborator Author

I tried using chatgpt and it managed to migrate this - pretty short - component:

image

@OlofSvahnVbg
Copy link
Collaborator Author

OlofSvahnVbg commented May 31, 2024

So react is probably going to launch a compiler some time this year (according to some sources). This compiler will render some functions and hooks obsolete (useCallback, useMemo).

The current migration from class component to function component involves memoization via useMemo, like this:

 const coordinatesModel = useMemo(
    () =>
      new CoordinatesModel({
        map: props.map,
        app: props.app,
        options: props.options,
        localObserver: localObserver,
      }),
    [props.map, props.app, props.options, localObserver]
  );

This will not be neccesary when the compiler comes out. But for now, it is.

If we remove useMemo with the current state of react, the coordinatesModel will initialize on every render, which is not ideal.
image

So, the question is: do we migrate with "compiler-code" or not?

(Compiler code being without memoization)

If we migrate with "compiler-code", we might see some performance issuses due to unecceasry initializations until the compiler comes out.

If we migrate without "compiler-code", we might have to remove useMemo etc. later when the compiler comes out.

Thougts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for adding/changing functionality
Projects
Status: Approved ideas
Development

No branches or pull requests

1 participant