mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
New Client: stable (#8426)
* try to freeze content object * deep freeze the content object, start to implement stable * freeze at the /common level * go back to freezing content only on the client * use deep-frezze-strict to support phantomjs * use own version of deepFreeze * update comment about deepFreeze
This commit is contained in:
20
website/client/libs/deepFreeze.js
Normal file
20
website/client/libs/deepFreeze.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// Code taken from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
|
||||
// and adapted
|
||||
export default function deepFreeze (obj) {
|
||||
// Retrieve the property names defined on obj
|
||||
const propNames = Object.getOwnPropertyNames(obj);
|
||||
const propNamesLength = propNames.length;
|
||||
|
||||
// Freeze properties before freezing self
|
||||
for (let i = 0; i < propNamesLength; i++) {
|
||||
const prop = obj[propNames[i]];
|
||||
|
||||
// Freeze prop if it is an object
|
||||
if (typeof prop === 'object' && prop !== null) {
|
||||
deepFreeze(prop);
|
||||
}
|
||||
}
|
||||
|
||||
// Freeze self (no-op if already frozen)
|
||||
return Object.freeze(obj);
|
||||
}
|
||||
Reference in New Issue
Block a user