[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
This commit is contained in:
Jorge Pinna Puissant
2022-02-25 12:35:44 +00:00
parent 221412630d
commit df944e3f9c
2 changed files with 0 additions and 51 deletions
@@ -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);
}
@@ -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() {