Skip to content

Commit

Permalink
fix: Overwriting hte combined instance values
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 committed Jan 15, 2025
1 parent 9f8df95 commit 94d13a4
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions platform/core/src/utils/combineFrameInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,25 @@ const combineFrameInstance = (frame, instance) => {
ImagePositionPatientToUse = [position[0], position[1], position[2]];
}
}
const sharedInstance = createCombinedValue(instance, SharedFunctionalGroupsSequence?.[0]);

// Cache the _parentInstance at the top level as a full copy to prevent
// setting values hard.
if (!instance._parentInstance) {
Object.defineProperty(instance, '_parentInstance', {
value: { ...instance },
});
}
const sharedInstance =
instance._shared ||
createCombinedValue(instance._parentInstance, SharedFunctionalGroupsSequence?.[0], '_shared');
const newInstance = createCombinedValue(
sharedInstance,
PerFrameFunctionalGroupsSequence?.[frameNumber]
PerFrameFunctionalGroupsSequence?.[frameNumber - 1],
`_shared-${frameNumber}`
);

Object.defineProperty(newInstance, 'ImagePositionPatient', {
value: ImagePositionPatientToUse ?? newInstance.ImagePositionPatient ?? [0, 0, frameNumber],
writable: true,
enumerable: true,
configurable: true,
});
newInstance.ImagePositionPatient = ImagePositionPatientToUse ??
newInstance.ImagePositionPatient ?? [0, 0, frameNumber];

Object.defineProperty(newInstance, 'frameNumber', {
value: frameNumber,
Expand All @@ -92,14 +99,25 @@ const combineFrameInstance = (frame, instance) => {
}
};

function createCombinedValue(parent, functionalGroups) {
/**
* Creates a combined instance stored in the parent object which
* inherits from the parent instance the attributes in the functional groups.
* The storage key in the parent is in key
*/
function createCombinedValue(parent, functionalGroups, key) {
if (parent[key]) {
return parent[key];
}
// Exclude any proxying values
const newInstance = Object.create(parent);
Object.defineProperty(parent, key, {
value: newInstance,
writable: false,
enumerable: false,
});
if (!functionalGroups) {
return newInstance;
}
if (functionalGroups._sharedValue) {
return functionalGroups._sharedValue;
}
const shared = functionalGroups
? Object.values(functionalGroups)
.filter(Boolean)
Expand All @@ -117,11 +135,6 @@ function createCombinedValue(parent, functionalGroups) {
newInstance[key] = value;
});
});
Object.defineProperty(functionalGroups, '_sharedValue', {
value: newInstance,
writable: false,
enumerable: false,
});
return newInstance;
}

Expand Down

0 comments on commit 94d13a4

Please sign in to comment.