Skip to content
Snippets Groups Projects
Verified Commit bd2c76a5 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: #6

parent 8b0d5f5b
Branches
Tags v1.18.0
No related merge requests found
......@@ -22,13 +22,13 @@ func (s *Settings[C]) OnChange(hook ChangeHook) *Settings[C] {
}
// HasOnChangeHook returns true if there are registered hooks.
func (s *Settings[C]) HasOnChangeHook(hook ChangeHook) *Settings[C] {
func (s *Settings[C]) HasOnChangeHook(hook ChangeHook) bool {
for _, h := range s.hooks.change {
if h == hook {
break
return true
}
}
return s
return false
}
// RemoveOnChangeHook removes a change hook from the list of hooks.
......
......@@ -18,13 +18,13 @@ func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] {
}
// HasOnErrorHook returns true if there are registered hooks.
func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] {
func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) bool {
for _, h := range s.hooks.error {
if h == hook {
break
return true
}
}
return s
return false
}
// RemoveOnErrorHook removes a change hook from the list of hooks.
......@@ -39,8 +39,23 @@ func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] {
}
func (s *Settings[C]) notifyErrorHooks() *Settings[C] {
if len(s.errors) == 0 {
return s
}
if len(s.hooks.error) == 0 {
return s
}
errors := make([]error, len(s.errors))
copy(errors, s.Errors())
s.ResetErrors()
for _, h := range s.hooks.error {
go h.Handle(ErrorEvent{})
go h.Handle(ErrorEvent{
Errors: errors,
})
}
return s
}
......@@ -8,14 +8,14 @@ import (
"reflect"
)
// ResetError is used to reset the error to nil
// ResetErrors is used to reset the error to nil
// After calling this function, the call HasErrors() will return false
func (s *Settings[C]) ResetErrors() *Settings[C] {
s.errors = []error{}
return s
}
// Check if the setting contains errors
// HasErrors checks if the setting contains errors
func (s *Settings[C]) HasErrors() bool {
return len(s.errors) > 0
}
......
......@@ -22,13 +22,13 @@ func (s *Settings[C]) OnPostprocessing(hook PostprocessingHook) *Settings[C] {
}
// HasOnPostprocessingHook returns true if there are registered hooks.
func (s *Settings[C]) HasOnPostprocessingHook(hook PostprocessingHook) *Settings[C] {
func (s *Settings[C]) HasOnPostprocessingHook(hook PostprocessingHook) bool {
for _, h := range s.hooks.postprocessing {
if h == hook {
break
return true
}
}
return s
return false
}
// RemoveOnPostprocessingHook removes a change hook from the list of hooks.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment