minor improvements and simplifications
This commit is contained in:
parent
d0f2fbc346
commit
cd8982ada0
3 changed files with 5 additions and 8 deletions
|
@ -21,13 +21,14 @@ func (spec *baseSpec) Receivers() []lib.Addressable {
|
|||
return spec.receivers
|
||||
}
|
||||
|
||||
func (spec *baseSpec) AddReceiver(rcv lib.Addressable) {
|
||||
func (spec *baseSpec) AddReceiver(rcv lib.Addressable) lib.ActionSpec {
|
||||
for _, r := range spec.receivers {
|
||||
if r == rcv {
|
||||
return
|
||||
return spec
|
||||
}
|
||||
}
|
||||
spec.receivers = append(spec.receivers, rcv)
|
||||
return spec
|
||||
}
|
||||
|
||||
func Base(hdlr lib.ActionHandler, rcvs ...string) *baseSpec {
|
||||
|
@ -38,10 +39,6 @@ func Base(hdlr lib.ActionHandler, rcvs ...string) *baseSpec {
|
|||
return &spec
|
||||
}
|
||||
|
||||
func BaseA(hdlr lib.ActionHandler, rcvs ...lib.Addressable) *baseSpec {
|
||||
return &baseSpec{hdlr, rcvs}
|
||||
}
|
||||
|
||||
// action selection
|
||||
|
||||
func Select(ctx lib.Context, msg lib.Message) []lib.Action {
|
||||
|
|
|
@ -40,7 +40,7 @@ func connect(src, tgt lib.Context, msg lib.Message) {
|
|||
}
|
||||
}
|
||||
}
|
||||
cfg.AddAction(pattern, action.BaseA(handle, tgt))
|
||||
cfg.AddAction(pattern, action.Base(handle).AddReceiver(tgt))
|
||||
}
|
||||
|
||||
func handle(act lib.Action) bool {
|
||||
|
|
|
@ -83,7 +83,7 @@ type Action interface {
|
|||
type ActionSpec interface {
|
||||
Handler() ActionHandler
|
||||
Receivers() []Addressable
|
||||
AddReceiver(Addressable)
|
||||
AddReceiver(Addressable) ActionSpec
|
||||
}
|
||||
|
||||
// procedures and handlers
|
||||
|
|
Loading…
Add table
Reference in a new issue