Skip to content

Commit e851b8b

Browse files
committed
Add a clone convenience method
1 parent ec6ee56 commit e851b8b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/cache/inmemory/readFromStore.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,7 @@ export class StoreReader {
659659
i,
660660
nextDataState === "partial" ?
661661
// avoid mutating the execResult partialBoundaries object
662-
new PartialBoundaries()
663-
.merge(execResult.partialBoundaries)
664-
.add(field)
662+
execResult.partialBoundaries.clone().add(field)
665663
: execResult.partialBoundaries
666664
);
667665

@@ -893,12 +891,18 @@ class PartialBoundaries {
893891
return this.children.get(key);
894892
}
895893

894+
clone() {
895+
return new PartialBoundaries().merge(this);
896+
}
897+
896898
set(key: string | number, boundary: PartialBoundaries) {
897899
const child = this.getChild(key);
898900

899901
this.children.set(
900902
key,
901-
child ? new PartialBoundaries().merge(child).merge(boundary) : boundary
903+
// Create a new PartialBoundaries instance to avoid mutating any cached
904+
// execResult partialBoundaries objects
905+
child ? child.clone().merge(boundary) : boundary
902906
);
903907
}
904908

0 commit comments

Comments
 (0)