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 index 336278077bc..142cd288049 100644 --- 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 @@ -5,41 +5,21 @@ const { Component } = owl; const { onPatched } = owl.hooks; /** - * Compares `a` and `b` up to the given `propsCompareDepth`. + * Shallow compares props `a` and `b`. * - * @param {any} a - * @param {any} b - * @param {Object|integer} propsCompareDepth + * @param {Object} a + * @param {Object} b * @returns {boolean} */ -function isEqual(a, b, propsCompareDepth) { +function isEqual(a, b) { const keys = Object.keys(a); if (Object.keys(b).length !== keys.length) { return false; } for (const key of keys) { - // the depth can be given either as a number (for all keys) or as - // an object (for each key) - let depth; - if (typeof propsCompareDepth === 'number') { - depth = propsCompareDepth; - } else { - depth = propsCompareDepth[key] || 0; - } - if (depth === 0 && a[key] !== b[key]) { + if (a[key] !== b[key]) { return false; } - if (depth !== 0) { - let nextDepth; - if (typeof depth === 'number') { - nextDepth = depth - 1; - } else { - nextDepth = depth; - } - if (!isEqual(a[key], b[key], nextDepth)) { - return false; - } - } } return true; } @@ -49,12 +29,8 @@ function isEqual(a, b, propsCompareDepth) { * 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. - * - * @param {Object} [param0={}] - * @param {Object} [param0.propsCompareDepth={}] allows to specify the comparison - * depth to use for each prop. Default is shallow compare (depth = 0). */ -export function useShouldUpdateBasedOnProps({ propsCompareDepth = {} } = {}) { +export function useShouldUpdateBasedOnProps() { const component = Component.current; let forceRender = false; component.shouldUpdate = nextProps => { @@ -68,7 +44,7 @@ export function useShouldUpdateBasedOnProps({ propsCompareDepth = {} } = {}) { allNewProps[key] = defaultProps[key]; } } - forceRender = !isEqual(component.props, allNewProps, propsCompareDepth); + 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 a8cc1718f53..c157d8ca82d 100644 --- a/addons/mail/static/src/utils/messaging_component.js +++ b/addons/mail/static/src/utils/messaging_component.js @@ -16,10 +16,8 @@ const componentRegistry = {}; * * @param {Component} ComponentClass the constructor of the component to be * registered. Its name will be used as its key in the registry. - * @param {Object} [param1] - * @param {Object} [param1.propsCompareDepth] @see useShouldUpdateBasedOnProps */ -export function registerMessagingComponent(ComponentClass, { propsCompareDepth = {} } = {}) { +export function registerMessagingComponent(ComponentClass) { const { defaultProps, components, name, props } = ComponentClass; if (componentRegistry[name]) { throw new Error(`There already is a registered component with the name "${name}"`); @@ -31,7 +29,7 @@ export function registerMessagingComponent(ComponentClass, { propsCompareDepth = setup() { this.root = useRef('root'); useModels(); - useShouldUpdateBasedOnProps({ propsCompareDepth }); + useShouldUpdateBasedOnProps(); super.setup(); } get className() {