Skip to content

Commit

Permalink
updated tagged hook methods to use h as short var
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Jan 28, 2023
1 parent b8d7609 commit 51ee1b5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tools/hook/tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ type TaggedHook[T Tagger] struct {

// CanTriggerOn checks if the current TaggedHook can be triggered with
// the provided event data tags.
func (p *TaggedHook[T]) CanTriggerOn(tags []string) bool {
if len(p.tags) == 0 {
func (h *TaggedHook[T]) CanTriggerOn(tags []string) bool {
if len(h.tags) == 0 {
return true // match all
}

for _, t := range tags {
if list.ExistInSlice(t, p.tags) {
if list.ExistInSlice(t, h.tags) {
return true
}
}
Expand All @@ -49,10 +49,10 @@ func (p *TaggedHook[T]) CanTriggerOn(tags []string) bool {

// PreAdd registers a new handler to the hook by prepending it to the existing queue.
//
// The fn handler will be called only if the event data tags satisfy p.CanTriggerOn.
func (p *TaggedHook[T]) PreAdd(fn Handler[T]) {
p.mainHook.PreAdd(func(e T) error {
if p.CanTriggerOn(e.Tags()) {
// The fn handler will be called only if the event data tags satisfy h.CanTriggerOn.
func (h *TaggedHook[T]) PreAdd(fn Handler[T]) {
h.mainHook.PreAdd(func(e T) error {
if h.CanTriggerOn(e.Tags()) {
return fn(e)
}

Expand All @@ -62,10 +62,10 @@ func (p *TaggedHook[T]) PreAdd(fn Handler[T]) {

// Add registers a new handler to the hook by appending it to the existing queue.
//
// The fn handler will be called only if the event data tags satisfy p.CanTriggerOn.
func (p *TaggedHook[T]) Add(fn Handler[T]) {
p.mainHook.Add(func(e T) error {
if p.CanTriggerOn(e.Tags()) {
// The fn handler will be called only if the event data tags satisfy h.CanTriggerOn.
func (h *TaggedHook[T]) Add(fn Handler[T]) {
h.mainHook.Add(func(e T) error {
if h.CanTriggerOn(e.Tags()) {
return fn(e)
}

Expand Down

0 comments on commit 51ee1b5

Please sign in to comment.