From 0e9fb00f7863593fa63a3adf2593fb48dfb168b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 20 Jan 2021 17:12:01 +0000 Subject: [FIX] mail: more consistent async handling of scroll feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit task-2333535 task-2388676 closes odoo/odoo#64505 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/bugfix/bugfix.js | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'addons/mail/static/src/bugfix/bugfix.js') diff --git a/addons/mail/static/src/bugfix/bugfix.js b/addons/mail/static/src/bugfix/bugfix.js index 1253e69da8e..162bf606db5 100644 --- a/addons/mail/static/src/bugfix/bugfix.js +++ b/addons/mail/static/src/bugfix/bugfix.js @@ -9,6 +9,44 @@ odoo.define('mail/static/src/bugfix/bugfix.js', function (require) { }); +// Should be moved to its own file in master. +odoo.define('mail/static/src/component_hooks/use_rendered_values/use_rendered_values.js', function (require) { +'use strict'; + +const { Component } = owl; +const { onMounted, onPatched } = owl.hooks; + +/** + * This hooks provides support for accessing the values returned by the given + * selector at the time of the last render. The values will be updated after + * every mount/patch. + * + * @param {function} selector function that will be executed at the time of the + * render and of which the result will be stored for future reference. + * @returns {function} function to call to retrieve the last rendered values. + */ +function useRenderedValues(selector) { + const component = Component.current; + let renderedValues; + let patchedValues; + + const __render = component.__render.bind(component); + component.__render = function () { + renderedValues = selector(); + return __render(...arguments); + }; + onMounted(onUpdate); + onPatched(onUpdate); + function onUpdate() { + patchedValues = renderedValues; + } + return () => patchedValues; +} + +return useRenderedValues; + +}); + // Should be moved to its own file in master. odoo.define('mail/static/src/component_hooks/use_update/use_update.js', function (require) { 'use strict'; -- cgit v1.2.3