Skip to content

Commit

Permalink
use COMPLEX_OPTION_COMPARATORS for view options. fixes memoization, w…
Browse files Browse the repository at this point in the history
…hich fixes recursion problems
  • Loading branch information
arshaw committed Jul 26, 2022
1 parent 1733a16 commit 43609b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 7 additions & 6 deletions packages/common/src/options.ts
Expand Up @@ -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)
}
Expand Down
12 changes: 10 additions & 2 deletions packages/common/src/reducers/CalendarDataManager.ts
Expand Up @@ -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]
}
Expand Down

0 comments on commit 43609b4

Please sign in to comment.