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

Debug string for WidgetValue #1971

Merged
merged 8 commits into from
Apr 22, 2024
Merged

Conversation

alec-manabat
Copy link
Collaborator

@alec-manabat alec-manabat commented Apr 16, 2024

Adds a "pretty printed" string to WidgetValue. This makes tests easier to debug

  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

@alec-manabat alec-manabat requested a review from swankjesse April 16, 2024 21:53

override fun toDebugString(): String {
val debugString = """
|ButtonValue(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think we should keep the "Value` suffix in this rendering? It's useful when referring to it in code, but I think in this rendering we might just want to use the widget name only.

Comment on lines 307 to 310
val childrenDebugString = childrenLists.joinToString(prefix = " {\n", postfix = "\n}", separator
= "\n") {
it.toDebugString().prependIndent(" ")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm having trouble picturing how a multi-children widget renders. It looks like maybe all of the children are put into a single set of curly braces? Meaning you wouldn't be able to differentiate between them.

You might consider making widgets with multiple children render them more like properties.

TestRowValue {  // Single children, renders with trailing lambda-like syntax
  MultiChildrenValue(
    front = {
      Button(..)
      Button(..)
    }
    back = {
      Text(..)
      Text(..)
    }
}

of course we could render all nodes like this, but it introduces an additional layer of nesting for the single-children case which is a bit annoying.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, currently they would all be in one set of braces. Will try to set it up like above 👍

Comment on lines 472 to 473
.addCode(
buildCodeBlock {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of calling .addCode and then buildCodeBlock and then things like addStatement, you can call apply which will give you the ability to do if/else and call addStatement and the like

@alec-manabat alec-manabat merged commit daf8f5a into trunk Apr 22, 2024
10 checks passed
@alec-manabat alec-manabat deleted the amanabat/widget-debug-string branch April 22, 2024 15:14
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.

2 participants