mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: simplify hook chain creation (#424)
* entc/gen: simplify hook chain creation Signed-off-by: Alex Snast <alexsn@fb.com> * circleci: upgrade orb versions Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
@@ -99,13 +99,11 @@ func NewChain(hooks ...ent.Hook) Chain {
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return func(mutator ent.Mutator) ent.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
next = c.hooks[i](next)
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user