Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM: Expose copy of layers from overlay document #23

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dom/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ func (m *overlayDocument) Search(fn SearchValueFunc) Coordinates {
return r
}

func (m *overlayDocument) Layers() []string {
c := make([]string, len(m.names))
copy(c, m.names)
func (m *overlayDocument) Layers() map[string]Container {
c := make(map[string]Container, len(m.names))
for n, v := range m.overlays {
c[n] = v.Clone().(Container)
}
return c
}

Expand Down
9 changes: 9 additions & 0 deletions dom/overlay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ func TestOverlaySearch(t *testing.T) {
res = d.Search(SearchEqual(2))
assert.Equal(t, 0, len(res))
}

func TestOverlayLayers(t *testing.T) {
d := NewOverlayDocument()
d.Put("layer1", "root.next.next2", LeafNode(1))
d.Put("layer2", "root.other", LeafNode(5))
m := d.Layers()
assert.Equal(t, 2, len(m))
assert.Equal(t, 5, m["layer2"].Children()["root"].(Container).Children()["other"].(Leaf).Value())
}
5 changes: 3 additions & 2 deletions dom/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ type OverlayDocument interface {
Put(overlay, path string, value Node)
// Merged returns read-only, merged view of all overlays
Merged(option ...MergeOption) Container
// Layers return copy of list with all layer names
Layers() []string
// Layers returns a copy of mapping between layer name and its associated Container.
// Containers are cloned using Node.Clone()
Layers() map[string]Container
}
Loading