support multiple mutations
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type MutationRegistry interface {
|
||||
Apply(grain any, msg proto.Message) error
|
||||
Apply(grain any, msg ...proto.Message) error
|
||||
RegisterMutations(handlers ...MutationHandler)
|
||||
Create(typeName string) (proto.Message, bool)
|
||||
GetTypeName(msg proto.Message) (string, bool)
|
||||
@@ -145,7 +145,7 @@ func (r *ProtoMutationRegistry) Create(typeName string) (proto.Message, bool) {
|
||||
// Returns updated grain if successful.
|
||||
//
|
||||
// If the mutation is not registered, returns (nil, ErrMutationNotRegistered).
|
||||
func (r *ProtoMutationRegistry) Apply(grain any, msg proto.Message) error {
|
||||
func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) error {
|
||||
if grain == nil {
|
||||
return fmt.Errorf("nil grain")
|
||||
}
|
||||
@@ -161,9 +161,10 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg proto.Message) error {
|
||||
if !ok {
|
||||
return ErrMutationNotRegistered
|
||||
}
|
||||
|
||||
if err := entry.Handle(grain, msg); err != nil {
|
||||
return err
|
||||
for _, m := range msg {
|
||||
if err := entry.Handle(grain, m); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// if entry.updateTotals {
|
||||
|
||||
Reference in New Issue
Block a user