Travis build: 342 [cron]
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -995,6 +995,26 @@
|
||||
"hash": "31714831376eeddd863a295af778632f584468745fbeb4e9a6f62b5275ea3562"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "deepFreeze",
|
||||
"type": "snippet",
|
||||
"attributes": {
|
||||
"fileName": "deepFreeze.md",
|
||||
"text": "Deep freezes an object.\n\nCalls `Object.freeze(obj)` recursively on all unfrozen properties of passed object that are `instanceof` object.",
|
||||
"codeBlocks": [
|
||||
"const deepFreeze = obj =>\n Object.keys(obj).forEach(\n prop =>\n !obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])\n ) || Object.freeze(obj);",
|
||||
"'use strict';\n\nconst o = deepFreeze([1, [2, 3]]);\n\no[0] = 3; // not allowed\no[1][0] = 4; // not allowed as well"
|
||||
],
|
||||
"tags": [
|
||||
"object",
|
||||
"recursion"
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "24b3dd66c4b69577d70917ba4f0c119a7ad21497d18704b7150c3693673b5e53"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "defaults",
|
||||
"type": "snippet",
|
||||
|
||||
@ -1,17 +1,6 @@
|
||||
const deepFreeze = obj => {
|
||||
Object.freeze(obj);
|
||||
|
||||
Object.getOwnPropertyNames(obj).forEach(function(prop) {
|
||||
if (
|
||||
obj.hasOwnProperty(prop) &&
|
||||
obj[prop] !== null &&
|
||||
(typeof obj[prop] === 'object' || typeof obj[prop] === 'function') &&
|
||||
!Object.isFrozen(obj[prop])
|
||||
) {
|
||||
deepFreeze(obj[prop]);
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
const deepFreeze = obj =>
|
||||
Object.keys(obj).forEach(
|
||||
prop =>
|
||||
!obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
|
||||
) || Object.freeze(obj);
|
||||
module.exports = deepFreeze;
|
||||
|
||||
3238
test/testlog
3238
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user