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

Refactor NavigationRequest object to data object #2391

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

yongsuk44
Copy link
Contributor

'data object' instead of a plain 'object' means that it automatically has a 'toString()' function without the need to override it manually

Link

@shobhitagarwal1612
Copy link
Member

/gcbrun

@shobhitagarwal1612
Copy link
Member

@yongsuk44 Can you please fix the failing build?

@yongsuk44
Copy link
Contributor Author

yongsuk44 commented Mar 31, 2024

@shobhitagarwal1612
sry, 'import' and Lint issues and fixed them.

Comment on lines +21 to +23
data object NavigateUp : NavigationRequest

data class NavigateTo(val directions: NavDirections) : NavigationRequest
data object FinishApp : NavigationRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rational behind changing it from object to data object? other than data object gives you the power to have a toString() function as written in the PR description, which just prints the name of the object

looks like an extra work we are trying to give to compiler to generate some functions for us, which we are currently not using.

WDYT?
Let me know if I am missing anything here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also adds more boilerplate it seems in referencing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment. 😀

@anandwana001
The functions generated by the data object, such as toString(), may not be used in production code, but they can be useful for debugging during development. This can be easily understood through a link.
Also, Requesting additional work from the compiler is also justified because the Kotlin compiler is optimized to handle methods like toString, equals, and hashCode (e.g., for data classes).

@gino-m
I understand that this leads to some additional boilerplate, but I think it has improved readability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the idea now, cool, let's have it.

@gino-m
Copy link
Collaborator

gino-m commented May 13, 2024

Running integration tests, they should complete shortly:

/gcbrun

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

Successfully merging this pull request may close these issues.

None yet

4 participants