From 659e7ca9757d786763b5fb2c6affc548894ce1cb Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Tue, 7 Sep 2021 06:22:13 +0000 Subject: [PATCH] [IMP] web: core: deepCopy function for Objects Part-of: odoo/odoo#73311 --- addons/web/static/src/core/utils/objects.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/web/static/src/core/utils/objects.js b/addons/web/static/src/core/utils/objects.js index 7962bdf01e3..4e7638b0b53 100644 --- a/addons/web/static/src/core/utils/objects.js +++ b/addons/web/static/src/core/utils/objects.js @@ -10,3 +10,14 @@ export function shallowEqual(obj1, obj2) { obj1Keys.every((key) => obj1[key] === obj2[key]) ); } + +/** + * Deep copies an object. As it relies on JSON this function as some limitations + * - no support for circular objects + * - no support for specific classes, that will at best be lost and at worst crash (Map, Set etc...) + * @param {Object} An object that is fully JSON stringifiable + * @return {Object} + */ +export function deepCopy(obj) { + return JSON.parse(JSON.stringify(obj)); +}