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

fix: #6

parent 8b0d5f5b
No related branches found
No related tags found
No related merge requests found
...@@ -22,13 +22,13 @@ func (s *Settings[C]) OnChange(hook ChangeHook) *Settings[C] { ...@@ -22,13 +22,13 @@ func (s *Settings[C]) OnChange(hook ChangeHook) *Settings[C] {
} }
// HasOnChangeHook returns true if there are registered hooks. // 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 { for _, h := range s.hooks.change {
if h == hook { if h == hook {
break return true
} }
} }
return s return false
} }
// RemoveOnChangeHook removes a change hook from the list of hooks. // RemoveOnChangeHook removes a change hook from the list of hooks.
......
...@@ -18,13 +18,13 @@ func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] { ...@@ -18,13 +18,13 @@ func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] {
} }
// HasOnErrorHook returns true if there are registered hooks. // 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 { for _, h := range s.hooks.error {
if h == hook { if h == hook {
break return true
} }
} }
return s return false
} }
// RemoveOnErrorHook removes a change hook from the list of hooks. // RemoveOnErrorHook removes a change hook from the list of hooks.
...@@ -39,8 +39,23 @@ func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] { ...@@ -39,8 +39,23 @@ func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] {
} }
func (s *Settings[C]) notifyErrorHooks() *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 { for _, h := range s.hooks.error {
go h.Handle(ErrorEvent{}) go h.Handle(ErrorEvent{
Errors: errors,
})
} }
return s return s
} }
...@@ -8,14 +8,14 @@ import ( ...@@ -8,14 +8,14 @@ import (
"reflect" "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 // After calling this function, the call HasErrors() will return false
func (s *Settings[C]) ResetErrors() *Settings[C] { func (s *Settings[C]) ResetErrors() *Settings[C] {
s.errors = []error{} s.errors = []error{}
return s return s
} }
// Check if the setting contains errors // HasErrors checks if the setting contains errors
func (s *Settings[C]) HasErrors() bool { func (s *Settings[C]) HasErrors() bool {
return len(s.errors) > 0 return len(s.errors) > 0
} }
......
...@@ -22,13 +22,13 @@ func (s *Settings[C]) OnPostprocessing(hook PostprocessingHook) *Settings[C] { ...@@ -22,13 +22,13 @@ func (s *Settings[C]) OnPostprocessing(hook PostprocessingHook) *Settings[C] {
} }
// HasOnPostprocessingHook returns true if there are registered hooks. // 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 { for _, h := range s.hooks.postprocessing {
if h == hook { if h == hook {
break return true
} }
} }
return s return false
} }
// RemoveOnPostprocessingHook removes a change hook from the list of hooks. // 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