From df944e3f9ce553b9fe82b0b4bca29ab174aabe03 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 25 Feb 2022 09:08:32 +0000 Subject: [PATCH] [REF] mail: remove the hook useShouldUpdateBasedOnProps With the new fine-grained reactivity in owl 2, this hook is not necessary any more. Part-of: odoo/odoo#84314 --- .../use_should_update_based_on_props.js | 49 ------------------- .../static/src/utils/messaging_component.js | 2 - 2 files changed, 51 deletions(-) delete mode 100644 addons/mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js diff --git a/addons/mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js b/addons/mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js deleted file mode 100644 index 90add18a6fa..00000000000 --- a/addons/mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js +++ /dev/null @@ -1,49 +0,0 @@ -/** @odoo-module **/ - -const { onPatched, useComponent } = owl; - -/** - * Shallow compares props `a` and `b`. - * - * @param {Object} a - * @param {Object} b - * @returns {boolean} - */ -function isEqual(a, b) { - const keys = Object.keys(a); - if (Object.keys(b).length !== keys.length) { - return false; - } - for (const key of keys) { - if (a[key] !== b[key]) { - return false; - } - } - return true; -} - -/** - * This hook overrides the `shouldUpdate` method to ensure the component is only - * updated if its props actually changed. This is especially useful to use on - * components for which an extra render costs proportionally a lot more than - * comparing props. - */ -export function useShouldUpdateBasedOnProps() { - const component = useComponent(); - let forceRender = false; - component.shouldUpdate = nextProps => { - if (forceRender) { - return true; - } - const allNewProps = Object.assign({}, nextProps); - const defaultProps = component.constructor.defaultProps; - for (const key in defaultProps) { - if (allNewProps[key] === undefined) { - allNewProps[key] = defaultProps[key]; - } - } - forceRender = !isEqual(component.props, allNewProps); - return forceRender; - }; - onPatched(() => forceRender = false); -} diff --git a/addons/mail/static/src/utils/messaging_component.js b/addons/mail/static/src/utils/messaging_component.js index 6228913a1bf..e002f475229 100644 --- a/addons/mail/static/src/utils/messaging_component.js +++ b/addons/mail/static/src/utils/messaging_component.js @@ -1,7 +1,6 @@ /** @odoo-module */ import { useModels } from "@mail/component_hooks/use_models/use_models"; -import { useShouldUpdateBasedOnProps } from "@mail/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props"; const { useRef } = owl; @@ -29,7 +28,6 @@ export function registerMessagingComponent(ComponentClass) { setup() { this.root = useRef('root'); useModels(); - useShouldUpdateBasedOnProps(); super.setup(); } get className() {