Fix captured variable

This commit is contained in:
Toby Padilla 2020-06-23 15:11:06 -05:00 committed by Christian Rocha
parent de147c5061
commit e90039d16e
1 changed files with 4 additions and 6 deletions

10
tea.go
View File

@ -87,8 +87,6 @@ func NewProgram(init Init, update Update, view View) *Program {
// Start initializes the program.
func (p *Program) Start() error {
var (
model Model
cmd Cmd
cmds = make(chan Cmd)
msgs = make(chan Msg)
errs = make(chan error)
@ -103,10 +101,10 @@ func (p *Program) Start() error {
defer restoreTerminal()
// Initialize program
model, cmd = p.init()
if cmd != nil {
model, initCmd := p.init()
if initCmd != nil {
go func() {
cmds <- cmd
cmds <- initCmd
}()
}
@ -180,7 +178,7 @@ func (p *Program) Start() error {
// Process internal messages for the renderer
mrRenderer.handleMessages(msg)
var cmd Cmd
model, cmd = p.update(msg, model) // run update
cmds <- cmd // process command (if any)
mrRenderer.write(p.view(model)) // send view to renderer