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:
Christian Rocha
2020-05-12 17:56:30 -04:00
parent 82ddbb8e12
commit ade8203c21
13 changed files with 136 additions and 322 deletions

View File

@@ -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)
})
}