Use model-based Tick commands in spinner examples

This commit is contained in:
Christian Rocha 2022-01-10 14:20:15 -05:00
parent ee92bed288
commit 843b6a5249
2 changed files with 4 additions and 4 deletions

View File

@ -28,7 +28,7 @@ func initialModel() model {
}
func (m model) Init() tea.Cmd {
return spinner.Tick
return m.spinner.Tick
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

View File

@ -44,7 +44,7 @@ type model struct {
}
func (m model) Init() tea.Cmd {
return spinner.Tick
return m.spinner.Tick
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@ -59,14 +59,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.index = len(spinners) - 1
}
m.resetSpinner()
return m, spinner.Tick
return m, m.spinner.Tick
case "l", "right":
m.index++
if m.index >= len(spinners) {
m.index = 0
}
m.resetSpinner()
return m, spinner.Tick
return m, m.spinner.Tick
default:
return m, nil
}