forked from Mirrors/bubbletea
Provisionally add `CmdMap` and `SubMap` functions
This commit is contained in:
parent
6e769686f1
commit
1bf93b1ccf
14
tea.go
14
tea.go
|
@ -18,6 +18,13 @@ type Model interface{}
|
|||
// Cmd is an IO operation. If it's nil it's considered a no-op.
|
||||
type Cmd func(Model) Msg
|
||||
|
||||
// CmdMap applies a given model to a command
|
||||
func CmdMap(cmd Cmd, model Model) Cmd {
|
||||
return func(_ Model) Msg {
|
||||
return cmd(model)
|
||||
}
|
||||
}
|
||||
|
||||
// Batch peforms a bunch of commands concurrently with no ordering guarantees
|
||||
// about the results.
|
||||
func Batch(cmds ...Cmd) Cmd {
|
||||
|
@ -30,6 +37,13 @@ func Batch(cmds ...Cmd) Cmd {
|
|||
// but there's really no reason to have a nil subscription.
|
||||
type Sub func(Model) Msg
|
||||
|
||||
// SubMap applies a given model to a subscription
|
||||
func SubMap(sub Sub, model Model) Sub {
|
||||
return func(_ Model) Msg {
|
||||
return sub(model)
|
||||
}
|
||||
}
|
||||
|
||||
// Subs is a keyed set of subscriptions. The key should be a unique
|
||||
// identifier; two different subscriptions should not have the same key
|
||||
type Subs map[string]Sub
|
||||
|
|
Loading…
Reference in New Issue