Skip to content

Commit

Permalink
feat(fields): read/set all the fields from the given struct
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
bkrukowski committed Oct 1, 2024
1 parent b3e3b53 commit aa03e94
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fields/iterate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func iterate(strct any, cfg *config, path []reflect.StructField) error {
cfg.getter(append(path, f), value)
}

var setterHasBeenTriggered bool
var valueHasChanged bool

value, setterHasBeenTriggered = trySetValue(f, value, cfg, path)
value, valueHasChanged = trySetValue(f, value, cfg, path)

if cfg.recursive && isStructOrNonNilStructPtr(f.Type, value) {
original := value
Expand All @@ -126,12 +126,10 @@ func iterate(strct any, cfg *config, path []reflect.StructField) error {
return intReflect.FieldCallbackResultStop()
}

if !reflect.DeepEqual(original, value) {
setterHasBeenTriggered = true
}
valueHasChanged = valueHasChanged || !reflect.DeepEqual(original, value)
}

if setterHasBeenTriggered {
if valueHasChanged {
return intReflect.FieldCallbackResultSet(value)
}

Expand Down

0 comments on commit aa03e94

Please sign in to comment.