fix(multiframe): handling proxies properly (#4693)
Co-authored-by: Bill Wallace <wayfarer3130@gmail.com> Co-authored-by: Chao Sui <chao.sui@curvebeamai.com>
This commit is contained in:
5 files changed
+44
-43
No files matched your search
@@ -67,18 +67,27 @@ 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 = createCombinedValue(
|
||||
instance._parentInstance,
|
||||
SharedFunctionalGroupsSequence?.[0],
|
||||
'_shared'
|
||||
);
|
||||
const newInstance = createCombinedValue(
|
||||
sharedInstance,
|
||||
PerFrameFunctionalGroupsSequence?.[frameNumber]
|
||||
PerFrameFunctionalGroupsSequence?.[frameNumber - 1],
|
||||
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,
|
||||
@@ -92,14 +101,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)
|
||||
@@ -117,11 +137,6 @@ function createCombinedValue(parent, functionalGroups) {
|
||||
newInstance[key] = value;
|
||||
});
|
||||
});
|
||||
Object.defineProperty(functionalGroups, '_sharedValue', {
|
||||
value: newInstance,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user