Update examples to use new subscription model

This commit is contained in:
Christian Rocha
2020-01-25 21:27:43 -05:00
parent 444c36b31f
commit 651b881a02
8 changed files with 49 additions and 26 deletions

View File

@@ -31,7 +31,7 @@ func main() {
initialize,
update,
view,
[]tea.Sub{tick, frame},
subscriptions,
)
if err := p.Start(); err != nil {
fmt.Println("could not start program:", err)
@@ -46,6 +46,18 @@ func initialize() (tea.Model, tea.Cmd) {
// SUBSCRIPTIONS
func subscriptions(model tea.Model) tea.Subs {
m, _ := model.(Model)
if !m.Chosen || m.Loaded {
return tea.Subs{
"tick": tick,
}
}
return tea.Subs{
"frame": frame,
}
}
func tick(model tea.Model) tea.Msg {
time.Sleep(time.Second)
return tickMsg{}