Closed Charliego3 closed 1 year ago
Hey! I think there is misunderstanding going on
Purpose of tea.Model
returned by Update
is state updating, internally it replaces model it was called with. Notice firstModel
isn't pointer type, but rather value type meaning fields won't be updated as it's effectively a copy of model and not "real" model.
What I'm implying here is that bubbletea
doesn't have to and won't ever compare previous model with returned model, Init
is called exactly once for root model, for child models it is your choice when, how and what do you call, bubbletea
has no control over anything that isn't root model.
As a rule of a thumb, you should never return different tea.Model
in Update
than function receiver one.
Code that replaces (updates) model in bubbletea loop: https://github.com/charmbracelet/bubbletea/blob/91dd1200733714c4fb7bc7ffb24af2c35cc2f111/tea.go#L398
As of what you are trying to make you might want to try out my library for bubbletea
called reactea
, it supports multiple views and such, might be an overkill for what you are trying to do.
https://github.com/londek/reactea/tree/v0.4.2
Best regards
Thank you very much, you are right, although this can achieve different pages, but I should not do this, reactea is I want.
Describe the bug As the title says, only
tea.NewProgram(model)
will call theInit()
function when there are multiple Models, and the Model returned by theUpdate
function has not been properly Init. In the following example,secondModel
returned byfirstModel.Update
does not callInit
, when the return value offirstModel.Update
is changed toreturn secondModel{s}, tea.Batch(tea.Println( f.input.Value()), s.Tick)
,spinner.Tick
will be consumed correctly. While this allows the program to run normally, it shouldn't be.Setup
Source Code
Expected behavior Hope Init can be called correctly. Instead of returning additional
spinner.Tick
Cmd when returningsecondModel
Screenshots
https://github.com/charmbracelet/bubbletea/assets/26761592/d15013d3-ae8d-432e-9abc-2028dbaea9f1