summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/utils.js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-03-21 15:30:58 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commiteaa66d11568b415b8d6b4c7a17a058b5ec1df4a6 (patch)
tree822fe86e984e69f989c3574936fe1792ae96fe9b /addons/web/static/src/js/core/utils.js
parente1eea38f2f940fbe252273a5a9d4d03474f81d0a (diff)
[REF] web: change internal representation of fields and view meta datas
* Data manager load_view returns a viewInfo object * ViewInfo contains: the arch, fields and fieldsInfo objects, and some extra informations * The fields come from the server and are frozen, without any view attributes (depend of the model). * The fieldsInfo contains every view attributes and informations.
Diffstat (limited to 'addons/web/static/src/js/core/utils.js')
-rw-r--r--addons/web/static/src/js/core/utils.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js
index 578eb3478f1..585be4d37b8 100644
--- a/addons/web/static/src/js/core/utils.js
+++ b/addons/web/static/src/js/core/utils.js
@@ -429,6 +429,33 @@ var utils = {
});
return str;
},
+ /**
+ * Visit a tree of objects, where each children are in an attribute 'children'.
+ * For each children, we call the callback function given in arguments.
+ *
+ * @param {Object} tree an object describing a tree structure
+ * @param {function} f a callback
+ */
+ traverse: function (tree, f) {
+ if (f(tree)) {
+ _.each(tree.children, function (c) { utils.traverse(c, f); });
+ }
+ },
+ /**
+ * Visit a tree of objects and freeze all
+ *
+ * @param {Object} obj
+ */
+ deepFreeze: function (obj) {
+ var propNames = Object.getOwnPropertyNames(obj);
+ propNames.forEach(function(name) {
+ var prop = obj[name];
+ if (typeof prop == 'object' && prop !== null)
+ utils.deepFreeze(prop);
+ });
+ return Object.freeze(obj);
+ },
+
};
return utils;