forked from Mirrors/bubbletea
Update example in README to use tea.Every
This commit is contained in:
parent
d503d5dbf6
commit
7b887b0a05
13
README.md
13
README.md
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
type model int
|
||||
|
||||
type tickMsg struct{}
|
||||
type tickMsg time.Time
|
||||
|
||||
func main() {
|
||||
p := tea.NewProgram(init, update, view, subscriptions)
|
||||
|
@ -37,7 +37,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
switch msg.(type) {
|
||||
case tickMsg:
|
||||
m--
|
||||
if m <= 0 {
|
||||
if m == 0 {
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
@ -53,14 +53,11 @@ func view(mdl tea.Model) string {
|
|||
// Subscribe to events
|
||||
func subscriptions(_ tea.Model) tea.Subs {
|
||||
return tea.Subs{
|
||||
"tick": tick,
|
||||
"tick": time.Every(time.Second, func(t time.Time) tea.Msg {
|
||||
return tickMsg(t)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func tick(_ tea.Model) tea.Msg {
|
||||
time.Sleep(time.Second)
|
||||
return tickMsg{}
|
||||
}
|
||||
```
|
||||
|
||||
Hungry for more? See the [other examples][examples].
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// NewEverMsg is used by Every to create a new message. It contains the time
|
||||
// NewEveryMsg is used by Every to create a new message. It contains the time
|
||||
// at which the timer finished.
|
||||
type NewEveryMsg func(time.Time) Msg
|
||||
|
||||
|
|
Loading…
Reference in New Issue