diff --git a/README.md b/README.md index 43f1310..91b831b 100644 --- a/README.md +++ b/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]. diff --git a/subscriptions.go b/subscriptions.go index b428d0a..9c4e95e 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -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