Skip to content

(v2) Is Bubbletea 2 going back to Init() (tea.Cmd)? #1336

Answered by meowgorithm
tuxtlequino asked this question in Q&A
Discussion options

You must be logged in to vote

We are so flattered you're not only trying v2, but bleeding edge v2-exp to boot!

In short, yes, we've settled on Init() tea.Cmd. After trying many different API shapes we've decided that's still the best way to do things, as one still has to initialize the model when passing it to the Program as an argument, which becomes a bit redundant with Init() (tea.Model, tea.Cmd):

type model int

func (m model) Init() (tea.Model, tea.Cmd) {
    m = 5 // we can initialize the model here
    return m, nil
}

p := tea.NewProgram(model(5)) // but we can also do it here

In theory, it would be nice to specify the type and eliminate the argument with generics, à la:

p := tea.NewProgram[model]()

…but there…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tuxtlequino
Comment options

@yhcote
Comment options

Answer selected by tuxtlequino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1333 on February 19, 2025 16:44.