mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
feat: export BatchMsg
There's no good reason to keep it private. Exporting it helps testability, debugging, and allows for a few special model.Update implementations.
This commit is contained in:
committed by
Christian Muehlhaeuser
parent
80f44c9384
commit
918d35746b
@@ -24,13 +24,13 @@ func Batch(cmds ...Cmd) Cmd {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return func() Msg {
|
return func() Msg {
|
||||||
return batchMsg(validCmds)
|
return BatchMsg(validCmds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// batchMsg is the internal message used to perform a bunch of commands. You
|
// BatchMsg is a message used to perform a bunch of commands concurrently with
|
||||||
// can send a batchMsg with Batch.
|
// no ordering guarantees. You can send a BatchMsg with Batch.
|
||||||
type batchMsg []Cmd
|
type BatchMsg []Cmd
|
||||||
|
|
||||||
// Sequence runs the given commands one at a time, in order. Contrast this with
|
// Sequence runs the given commands one at a time, in order. Contrast this with
|
||||||
// Batch, which runs commands concurrently.
|
// Batch, which runs commands concurrently.
|
||||||
|
|||||||
@@ -94,13 +94,13 @@ func TestBatch(t *testing.T) {
|
|||||||
})
|
})
|
||||||
t.Run("single cmd", func(t *testing.T) {
|
t.Run("single cmd", func(t *testing.T) {
|
||||||
b := Batch(Quit)()
|
b := Batch(Quit)()
|
||||||
if l := len(b.(batchMsg)); l != 1 {
|
if l := len(b.(BatchMsg)); l != 1 {
|
||||||
t.Fatalf("expected a []Cmd with len 1, got %d", l)
|
t.Fatalf("expected a []Cmd with len 1, got %d", l)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("mixed nil cmds", func(t *testing.T) {
|
t.Run("mixed nil cmds", func(t *testing.T) {
|
||||||
b := Batch(nil, Quit, nil, Quit, nil, nil)()
|
b := Batch(nil, Quit, nil, Quit, nil, nil)()
|
||||||
if l := len(b.(batchMsg)); l != 2 {
|
if l := len(b.(BatchMsg)); l != 2 {
|
||||||
t.Fatalf("expected a []Cmd with len 2, got %d", l)
|
t.Fatalf("expected a []Cmd with len 2, got %d", l)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
2
tea.go
2
tea.go
@@ -295,7 +295,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
|||||||
// NB: this blocks.
|
// NB: this blocks.
|
||||||
p.exec(msg.cmd, msg.fn)
|
p.exec(msg.cmd, msg.fn)
|
||||||
|
|
||||||
case batchMsg:
|
case BatchMsg:
|
||||||
for _, cmd := range msg {
|
for _, cmd := range msg {
|
||||||
cmds <- cmd
|
cmds <- cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func TestTeaBatchMsg(t *testing.T) {
|
|||||||
m := &testModel{}
|
m := &testModel{}
|
||||||
p := NewProgram(m, WithInput(&in), WithOutput(&buf))
|
p := NewProgram(m, WithInput(&in), WithOutput(&buf))
|
||||||
go func() {
|
go func() {
|
||||||
p.Send(batchMsg{inc, inc})
|
p.Send(BatchMsg{inc, inc})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
|
|||||||
Reference in New Issue
Block a user