mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
Remove entire subscription model
It was a valiant effort, and the implementation was solid and dependable, but at the end of the day we can achieve the same functionality in a much simpler fashion with commands, especially because Go is not held to the same restrictions as Elm.
This commit is contained in:
@@ -14,21 +14,17 @@ type model int
|
||||
|
||||
type tickMsg time.Time
|
||||
|
||||
func newTickMsg(t time.Time) boba.Msg {
|
||||
return tickMsg(t)
|
||||
}
|
||||
|
||||
func main() {
|
||||
boba.AltScreen()
|
||||
defer boba.ExitAltScreen()
|
||||
err := boba.NewProgram(initialize, update, view, subscriptions).Start()
|
||||
err := boba.NewProgram(initialize, update, view).Start()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
return model(5), nil
|
||||
return model(5), tick()
|
||||
}
|
||||
|
||||
func update(message boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
@@ -51,19 +47,20 @@ func update(message boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
if m <= 0 {
|
||||
return m, boba.Quit
|
||||
}
|
||||
return m, tick()
|
||||
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func subscriptions(_ boba.Model) boba.Subs {
|
||||
return boba.Subs{
|
||||
"tick": boba.Every(time.Second, newTickMsg),
|
||||
}
|
||||
}
|
||||
|
||||
func view(mdl boba.Model) string {
|
||||
m, _ := mdl.(model)
|
||||
return fmt.Sprintf("\n\n Hi. This program will exit in %d seconds...", m)
|
||||
}
|
||||
|
||||
func tick() boba.Cmd {
|
||||
return boba.Tick(time.Second, func(t time.Time) boba.Msg {
|
||||
return tickMsg(t)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user