refactor: Clone context when a view is cloned (#2493)
This commit is contained in:
committed by
dermotduffy
parent
3f0d2ef14d
commit
2acec49b29
+20
-1
@@ -87,7 +87,10 @@ describe('View Basics', () => {
|
||||
|
||||
expect(evolved.view).toBe(view.view);
|
||||
expect(evolved.camera).toBe(view.camera);
|
||||
expect(evolved.context).toBe(view.context);
|
||||
|
||||
// Context is deep-cloned if not set, so the evolved view owns it.
|
||||
expect(evolved.context).not.toBe(view.context);
|
||||
expect(evolved.context).toEqual(view.context);
|
||||
|
||||
// Query and QueryResults are cloned if not set.
|
||||
expect(evolved.query).not.toBe(view.query);
|
||||
@@ -96,6 +99,22 @@ describe('View Basics', () => {
|
||||
expect(evolved.queryResults).toEqual(view.queryResults);
|
||||
});
|
||||
|
||||
it('should isolate inherited context from mutation on clone and evolve', () => {
|
||||
const view = createView({
|
||||
view: 'live',
|
||||
camera: 'camera-1',
|
||||
context: { live: { overrides: new Map([['camera-1', 'sub-1']]) } },
|
||||
});
|
||||
|
||||
const cloned = view.clone();
|
||||
const evolved = view.evolve({});
|
||||
|
||||
cloned.context?.live?.overrides?.set('camera-1', 'mutated-clone');
|
||||
evolved.context?.live?.overrides?.delete('camera-1');
|
||||
|
||||
expect(view.context?.live?.overrides?.get('camera-1')).toBe('sub-1');
|
||||
});
|
||||
|
||||
it('should not clone query and queryResults with nothing set', () => {
|
||||
const view = createView();
|
||||
const evolved = view.evolve({});
|
||||
|
||||
Reference in New Issue
Block a user