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:
Alex Snast
2020-04-07 08:11:33 +03:00
committed by GitHub
parent d52d5120fd
commit 1b0e5ffaf4
26 changed files with 77 additions and 126 deletions

View File

@@ -86,13 +86,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -86,13 +86,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -86,13 +86,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -86,13 +86,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -73,13 +73,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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}