From eaa66d11568b415b8d6b4c7a17a058b5ec1df4a6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 21 Mar 2017 15:30:58 +0100 Subject: [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. --- addons/web/static/src/js/core/utils.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'addons/web/static/src/js/core/utils.js') 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; -- cgit v1.2.3