Skip to content

Commit 0f29914

Browse files
committed
chore: special case: incremental overlay can adjust the most recent action rather than constantly add
1 parent 5267c73 commit 0f29914

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmd/wasm/functions.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string,
2424

2525
// we go from the original to a new version, then look at the extra overlays on top
2626
// of that, then add that to the existing overlay
27-
var overlayDocument overlay.Overlay
28-
err = yaml.Unmarshal([]byte(existingOverlay), &overlayDocument)
27+
var existingOverlayDocument overlay.Overlay
28+
err = yaml.Unmarshal([]byte(existingOverlay), &existingOverlayDocument)
2929
if err != nil {
3030
return "", fmt.Errorf("failed to parse overlay schema: %w", err)
3131
}
3232
// now modify the original using the existing overlay
33-
err = overlayDocument.ApplyTo(&orig)
33+
err = existingOverlayDocument.ApplyTo(&orig)
3434
if err != nil {
3535
return "", fmt.Errorf("failed to apply existing overlay: %w", err)
3636
}
@@ -39,10 +39,15 @@ func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string,
3939
if err != nil {
4040
return "", fmt.Errorf("failed to compare schemas: %w", err)
4141
}
42-
// Now we take those actions, add them onto the end of the existing overlay
43-
overlayDocument.Actions = append(overlayDocument.Actions, newOverlay.Actions...)
42+
// special case, is there only one action and it targets the same as the last overlayDocument.Actions item entry, we'll just replace it.
43+
if len(newOverlay.Actions) == 1 && len(existingOverlayDocument.Actions) > 0 && newOverlay.Actions[0].Target == existingOverlayDocument.Actions[len(existingOverlayDocument.Actions)-1].Target {
44+
existingOverlayDocument.Actions[len(existingOverlayDocument.Actions)-1] = newOverlay.Actions[0]
45+
} else {
46+
// Otherwise, we'll just append the new overlay to the existing overlay
47+
existingOverlayDocument.Actions = append(existingOverlayDocument.Actions, newOverlay.Actions...)
48+
}
4449

45-
out, err := yaml.Marshal(overlayDocument)
50+
out, err := yaml.Marshal(existingOverlayDocument)
4651
if err != nil {
4752
return "", fmt.Errorf("failed to marshal schema: %w", err)
4853
}

web/src/assets/wasm/lib.wasm

711 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)