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