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

Fix deepFreeze #657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions src/sbvr-api/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,20 +714,20 @@ const onceGetter = <T, U extends keyof T>(
});
};

const deepFreezeExceptDefinition = (obj: AnyObject) => {
Object.freeze(obj);

const deepFreeze = (obj: AnyObject) => {
for (const prop of Object.getOwnPropertyNames(obj)) {
// We skip the definition because we know it's a property we've defined that will throw an error in some cases
const value = obj[prop];
if (
prop !== 'definition' &&
obj.hasOwnProperty(prop) &&
obj[prop] !== null &&
!['object', 'function'].includes(typeof obj[prop])
// `synonyms` is changed later on in the constrainedAbstractSqlModel.symbols get proxy
// `tables` is changed later on in the constrainedAbstractSqlModel.tables get proxy
!['synonyms', 'tables'].includes(prop) &&
Comment on lines +721 to +723
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the _.cloneDeep in

const constrainedAbstractSqlModel = _.cloneDeep(abstractSqlModel);
not remove the deep-freezing? Because the cloning is intended to avoid hitting issues with modifying the original model which is deep frozen, but if it's not removing the freezing as part of the cloning then that probably needs dealing with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Page- from my understanding the constrainedAbstractSqlModel should be deep frozen after the deepClone was made.
The freezing part applies to the constrainedAbstractSqlModel and at runtime the Proxies manipulate the dee frozen Object by writing parts to it through the proxies.

So I don't see that the _.cloneDeep is part of the freeze, please correct me here!

value !== null &&
(typeof value === 'object' || typeof value === 'function')
) {
deepFreezeExceptDefinition(obj);
deepFreeze(value);
}
}
Object.freeze(obj);
};

const createBypassDefinition = (definition: Definition) =>
Expand Down Expand Up @@ -1095,7 +1095,7 @@ const getBoundConstrainedMemoizer = memoizeWeak(
},
},
);
deepFreezeExceptDefinition(constrainedAbstractSqlModel);
deepFreeze(constrainedAbstractSqlModel);
return constrainedAbstractSqlModel;
},
{
Expand Down