From d6ffbfd479fcd235e6e8fdad2cbd84286ca359b6 Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Mon, 13 Jul 2020 13:14:32 +0000 Subject: [IMP] web: Model: extensions registry Refactoring of the Model class of `model.js` to support multiple extensions. The purpose is to build a model having the appropriate modules for a given situation. For instance, we don't need the control panel model if we don't have a control panel to start with. Some logic of the control panel model (which was until now the "main" search model) has been given to another model extension named "Search Model Extension" which will synchronize the informations of all models providing search data (domain, context, etc.). The model instantiated in the actions/views is now an instance of the "Action Model" (which directly extends the Model) and is meant to replace the view model in the long term. It might however need some improvements to hold such a role (partial interface rendering, etc.). Part of task 2228968 Co-authored-by: Julien Mougenot Co-authored-by: Mathieu Duckerts-Antoine --- addons/web/static/src/js/core/utils.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 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 17ce0e080b2..a5a5f4eb465 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -571,6 +571,31 @@ var utils = { str = "" + str; return new Array(size - str.length + 1).join('0') + str; }, + /** + * @param {any[]} arr + * @param {Function} fn + * @returns {any[]} + */ + partitionBy(arr, fn) { + let lastGroup = false; + let lastValue; + return arr.reduce((acc, cur) => { + let curVal = fn(cur); + if (lastGroup) { + if (curVal === lastValue) { + lastGroup.push(cur); + } else { + lastGroup = false; + } + } + if (!lastGroup) { + lastGroup = [cur]; + acc.push(lastGroup); + } + lastValue = curVal; + return acc; + }, []); + }, /** * Patch a class and return a function that remove the patch * when called. -- cgit v1.2.3