diff options
| author | alexkuhn <alexkuhn@users.noreply.github.com> | 2017-10-27 11:43:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-27 11:43:51 +0200 |
| commit | 49b8eed40857a9e352c8c9b8c90715a065eccd5c (patch) | |
| tree | 91cfbf067f3b1a9f7c15aced5be9fdd4b1b92619 /addons/web/static/src/js/core/utils.js | |
| parent | 7ed9a7fabeb613bf8b2c2980190399e8f9bbaa2b (diff) | |
[IMP] web: new utils function traversePath (#20521)
Enhanced version of the traverse function in utils,
so that it also builds the paths to any tree element.
There is a function visit in /enterprise/web_enterprise/static/src/js/app_switcher.js that has almost the same purpose as traverse in /odoo/addons/web/static/src/js/utility.js.
It seems more appropriate to move visit to utility.js.
Also, in order to keep good performance of traverse, it might be better to add an additional 'enhanced' version of traverse instead of making changes on traverse.
Hence the newly added function traversePath.
Diffstat (limited to 'addons/web/static/src/js/core/utils.js')
| -rw-r--r-- | addons/web/static/src/js/core/utils.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js index ac9310dce90..3fc88ac5b20 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -458,6 +458,20 @@ var utils = { } }, /** + * Enhanced traverse function with 'path' building on traverse. + * + * @param {Object} tree an object describing a tree structure + * @param {function} f a callback + * @param {Object} path the path to the current 'tree' object + */ + traversePath: function (tree, f, path) { + path = path || []; + f(tree, path); + _.each(tree.children, function (node) { + utils.traversePath(node, f, path.concat(tree)); + }); + }, + /** * Visit a tree of objects and freeze all * * @param {Object} obj |
