Programs should take an init type/function as the first argument

This is in line with the way Elm works. Also update examples.
This commit is contained in:
Christian Rocha
2020-01-18 22:18:19 -05:00
parent 068c7291fb
commit 6a0489592f
7 changed files with 44 additions and 25 deletions

View File

@@ -28,7 +28,7 @@ type frameMsg struct{}
func main() {
p := tea.NewProgram(
Model{0, false, 10, 0, 0, false},
initialize,
update,
view,
[]tea.Sub{tick, frame},
@@ -38,6 +38,12 @@ func main() {
}
}
// INIT
func initialize() (tea.Model, tea.Cmd) {
return Model{0, false, 10, 0, 0, false}, nil
}
// SUBSCRIPTIONS
func tick(model tea.Model) tea.Msg {