-
Notifications
You must be signed in to change notification settings - Fork 281
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
Components do not satisfy tea.Model interface #190
Comments
Just ran into this myself when trying to make a spinner UI component configurable. I'm not blocked on this since I'll probably just use it as a reason to break up my monolithic UI and use composition instead of configuration, but it does seem like these types should conform to |
This would indeed be useful. In order to create a form which supports multiple input types, in an extensible manner, I've had to create a new interface in order to compensate for the method signatures not matching. |
Just a note that if this is something you need right now you can go ahead and wrap existing components so that they satisfy func (m myViewport) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
m.actualViewport, cmd = m.actualViewport.Update(msg)
return m
}
// ...and then also wrap Init and View. Otherwise, in terms of idiomatic Go, the saying goes “accept interfaces, return structs.” While the gains here will be composability, the tradeoff will be additional assertions on returned // Update a child model.
newModel, cmd := viewport.Update(msg)
if vp, ok := newModel.(viewport.Model); ok {
m.viewport = vp
} That's not to say we're not in favor of the change, but something to bear in mind. |
I came here wondering about the same thing. I ran into this issue in a text-based game I was working on. It has a Bubble Tea's architecture and examples seem to encourage composability, so it feels odd that the components in this library are not composable in this manner. I think the "accept interfaces, return structs" point is valid, but at the same time, it could be argued that |
Based on charmbracelet#462 and charmbracelet#452 by @londek, but fixes maintaining the current visibility state across altscreen state changes. This makes the behavior consistent across terminals, some of which keep separate state for altscreen and regular buffer. Fixes charmbracelet#190.
Hey, just an update on this - we're working on a solution internally for |
Related: #717 |
Rationale: I want to write a function that works with any kind of component. I'm not seeing how to achieve this cleanly, since components actually do not satisfy the
github.com/charmbracelet/bubbletea.Model
interface. Please correct me if I'm misunderstanding something; I'm totally new to bubbletea!Problem 1. Missing
Init
method. Affected components:Not affected: progress, stopwatch, timer, viewport.
Problem 2. The
Update
method returns concrete component'sModel
, which makes it incompatible withtea.Model
:Backwards compatibility aside, consider using a type parameter in declaration of
tea.Model
:This is still suboptimal for sure; alternatively
Update
could simply returntea.Model
which the user then would have to downcast back to component's specific model.The text was updated successfully, but these errors were encountered: