From 43609b4377af1db5d159a1ba2f1cd31b8ffce252 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Tue, 26 Jul 2022 19:05:12 -0400 Subject: [PATCH] use COMPLEX_OPTION_COMPARATORS for view options. fixes memoization, which fixes recursion problems --- packages/common/src/options.ts | 13 +++++++------ packages/common/src/reducers/CalendarDataManager.ts | 12 ++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/common/src/options.ts b/packages/common/src/options.ts index 23ae84177f..c5e280fe43 100644 --- a/packages/common/src/options.ts +++ b/packages/common/src/options.ts @@ -378,14 +378,15 @@ export type CalendarOptionsRefined = export const COMPLEX_OPTION_COMPARATORS: { [optionName in keyof CalendarOptions]: (a: CalendarOptions[optionName], b: CalendarOptions[optionName]) => boolean } = { - headerToolbar: isBoolComplexEqual, - footerToolbar: isBoolComplexEqual, - buttonText: isBoolComplexEqual, - buttonHints: isBoolComplexEqual, - buttonIcons: isBoolComplexEqual, + headerToolbar: isMaybeObjectsEqual, + footerToolbar: isMaybeObjectsEqual, + buttonText: isMaybeObjectsEqual, + buttonHints: isMaybeObjectsEqual, + buttonIcons: isMaybeObjectsEqual, + dateIncrement: isMaybeObjectsEqual, } -function isBoolComplexEqual(a, b) { +function isMaybeObjectsEqual(a, b) { if (typeof a === 'object' && typeof b === 'object' && a && b) { // both non-null objects return isPropsEqual(a, b) } diff --git a/packages/common/src/reducers/CalendarDataManager.ts b/packages/common/src/reducers/CalendarDataManager.ts index 48a45de1cd..743744578e 100644 --- a/packages/common/src/reducers/CalendarDataManager.ts +++ b/packages/common/src/reducers/CalendarDataManager.ts @@ -527,10 +527,18 @@ export class CalendarDataManager { let extra = {} for (let optionName in raw) { - if (raw[optionName] === currentRaw[optionName]) { + if ( + raw[optionName] === currentRaw[optionName] || + (COMPLEX_OPTION_COMPARATORS[optionName] && + COMPLEX_OPTION_COMPARATORS[optionName](raw[optionName], currentRaw[optionName])) + ) { refined[optionName] = currentRefined[optionName] } else { - if (raw[optionName] === this.currentCalendarOptionsInput[optionName]) { + if ( + raw[optionName] === this.currentCalendarOptionsInput[optionName] || + (COMPLEX_OPTION_COMPARATORS[optionName] && + COMPLEX_OPTION_COMPARATORS[optionName](raw[optionName], this.currentCalendarOptionsInput[optionName])) + ) { if (optionName in this.currentCalendarOptionsRefined) { // might be an "extra" prop refined[optionName] = this.currentCalendarOptionsRefined[optionName] }