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

Dynamic stringer list item #319

Open
nervo opened this issue Jun 12, 2024 · 0 comments
Open

Dynamic stringer list item #319

nervo opened this issue Jun 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@nervo
Copy link
Contributor

nervo commented Jun 12, 2024

In upcoming list component, i've noticed that you can add items of any type.

There is a switch in Tree.Child method to handle this properly (see:

func (t *Tree) Child(children ...any) *Tree {
).

In cases of simple custom application items, one can choose between two options:

  • implement Node interface (see:
    type Node interface {
    ): value is then computed dynamically (during render time), BUT, you MUST implement Value, Children and Hidden methods, even if you don't really need them
  • implement go Stringer interface, which, in this case, is converted to a Leaf (see:
    case fmt.Stringer:
    ) . Sadly, the value is now strictly static (obtained during implementation, without the possibility of mutation during the item lifetime).

I think the Leaf struct should keep the Stringer as a property, and call its String() method during the render time, via its Value() method.
This way, it will become totally dynamic, and give the option to change its value during the item lifetime.

And if you're ok with that, i can make a pull request :)

@nervo nervo added the enhancement New feature or request label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant